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
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
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.