0
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    Options +FollowSymLinks
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L]
</IfModule>

I tried this code snippet for URL rewrite and it is not working.

1
  • Maybe mod rewrite is not installed? The snippet looks fine. Or your problem is because of trailing slashes? You might insert this line too: RewriteRule ^(.*)/$ /$1 [L,R=301] Commented Oct 31, 2016 at 14:03

1 Answer 1

1

According to me your public/.htaccess file should be like:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Also please check that you've enabled mod rewrite in your apache via editing php.ini & httpd.conf file.

You can also follow these steps (Link) to make your mod_rewrite URLs work

Don't forget to restart the Apache Service after doing this.

sudo apachectl restart // For MacOS
sudo service apache2 restart // For Ubuntu
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.