Allowing a . within the Rewrite Rule

Using mod_rewrite to handle various content issues

And while we are at it....

Postby anawaz » Wed Jul 29, 2009 12:02 pm

Here is another question:

RewriteRule ^([^/]+\.[^/]+)$ ./index.php?vwebsite=$1 [L]

I've got this going to get http://www.mydomain.com/anotherdomain.com to resolve in the background to http://www.mydomain.com/?vwebsite=anotherdomain.com.

However, now, I want all requests that go to http://www.mydomain.com/?vwebsite=anotherdomain.com in the browser to autmatically be 301'd to http://www.mydomain.com/anotherdomain.com so the URL is prermanently SEO friendly.

Trying the following, but clearly I am missing something!

Code: Select all
RewriteCond %{QUERY_STRING} ^vwebsite=(.*)$
  RewriteRule ^index\.php$ http://www.mydomain.com/$1? [R=301,L]


Thanks again, Richard.
anawaz
 
Posts: 7
Joined: Wed Jul 15, 2009 1:49 am
Location: London

Postby richardk » Wed Jul 29, 2009 4:05 pm

You need
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$

to stop loops. (It only matches new requests, not the internal mod_rewrite sub requests.)

Variables from RewriteConds are %n not $n.

If you know the vwebsite variable should match [^/]+\.[^/]+, use it.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?vwebsite=([^/]+\.[^/]+)(&.*)?$ [NC]
RewriteRule ^(index\.php)?$ http://www.example.com/%2? [R=301,L]

RewriteRule ^([^/]+\.[^/]+)$ /index.php?vwebsite=$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Previous

Return to Content

Who is online

Users browsing this forum: No registered users and 2 guests

cron