skip to Main Content

I’m using mode rewrite to make seo friendly urls. Please see the code below

Options +FollowSymLinks
RewriteEngine on

RewriteRule discover/([0-9]+)$ discover.php?page=$1 [NC,L]
RewriteRule ^([^.]+)$ $1.php [NC,L]

Code work in my local host but in the hosting server it doesn’t work.

If i added with the file extension it works in the server but without the extension it doesn’t work.

Ex: below works

RewriteRule discover-([0-9]+).html$ /discover.php?page=$1 [L]

Any pointers on how to make the 1st code it work? Appreciate your help.

2

Answers


  1. Turn off MultiViews option and check for existence of .php file before adding .php in a request:

    Options +FollowSymLinks -MultiViews
    RewriteEngine on
    
    RewriteRule discover/([0-9]+)/?$ discover.php?page=$1 [NC,L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/?$ $1.php [L]
    
    Login or Signup to reply.
  2. Try this too,

    Options +FollowSymLinks -MultiViews
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^discover/([0-9]+)$ discover.php?page=$1 [NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([^.]+)$ $1.php [NC,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search