Home > front end >  Basic .htaccess rewrite rule issue
Basic .htaccess rewrite rule issue

Time:09-17

I'm trying to set up some rules using a .htaccess file:

I want any url of this type: / to forward to index.php?name=X and any url with /postalcode/(anything here) to forward to index.php?postalcode=(anything here)

Here is what I did:

RewriteRule ^([^/]*)/$ index.php?name=$1 [L]
RewriteRule ^([^/postalcode/]*)/$ index.php?postalcode=$1 [L]

The first rule works but the second not. Any help please?

Thanks.

CodePudding user response:

Have your .htaccess like this:

RewriteEngine On

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# postal code handler
RewriteRule ^postalcode/([^/] )/?$ index.php?postalcode=$1 [L,QSA,NC]

# name handler
RewriteRule ^([^/] )/?$ index.php?name=$1 [L,QSA]
  • Related