Jump to content

URL rewrite mask


soycharliente

Recommended Posts

I thought by adding a rewrite condition to my htaccess file, I could generate some better looking URLs. When I have the following rewrite applied

RewriteRule ^state/([a-z]{2}) http://domain.tld/index.php?state=$1 [NC]

and try to visit the "better looking" URL, it forwards to the "ugly" one.

 

Am I missing something?

Here's the whole file too:

AuthType Basic
AuthName "Development Area"
AuthUserFile /path/to/the/file/.htpasswd
Require valid-user

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain.tld [NC]
RewriteRule ^(.*) http://domain.tld/$1 [L,R=301]

RewriteRule ^state/([a-z]{2}) http://domain.tld/index.php?state=$1 [NC]
</IfModule>

Link to comment
https://forums.phpfreaks.com/topic/200066-url-rewrite-mask/
Share on other sites

It's because you included the full URL in the rewritten path, not a server path.

 

AuthType Basic
AuthName "Development Area"
AuthUserFile /path/to/the/file/.htpasswd
Require valid-user

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain.tld [NC]
RewriteRule ^(.*) http://domain.tld/$1 [L,R=301]

RewriteRule ^state/([a-z]{2}) /index.php?state=$1 [NC]
</IfModule>

Link to comment
https://forums.phpfreaks.com/topic/200066-url-rewrite-mask/#findComment-1050094
Share on other sites

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.