Forum Moderators: phranque
ErrorDocument 404 /error.php
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.co.uk(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^(.*) /folder/file1.php?show=%1&cat=$1 [L]
which should mod_rewrite:
to
http://www.example.co.uk/folder/file1.php?show=subdomain&cat=page
Thanks
Mike
Hoever, what is the purpose of this line?
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
1) "\1$" is an atomic back-reference that will only work on some regex libraries.
2) When this RewriteCond matches, that means the pattern *does not* match, because of the logical "NOT" at the beginning of the pattern. Therefore, you will not be able to back-reference "%1" in the RewriteRule, because it will be blank.
Depending on what you're trying to do, it may just be a matter of moving your third rewritecond to make it the last one. Or maybe not...
It might be helpful to comment your intent for each line here, just to save guessing and wasting a bunch of time.
Jim
to mod_rewrite from:
http://www.example.co.uk/folder/file1.php?show=subdomain&cat=page
I had this in my htaccess file:
RewriteRule ^(.*).example.co.uk/(.*)/ /insurers/about1.php?show=$1&cat=$2 [L]
but that didn't work so I picked up the code in my original post from a WebmasterWorld thread.
RewriteEngine on
#
# Redirect all variants of example.co.uk to www.example.co.uk
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Redirect non-canonical subdomains to canonical subdomains
# (Only case errors in the subdomain name itself won't be corrected)
RewriteCond %{HTTP_HOST} !^[^.]+\.example\.co\.uk$
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.co\.uk [NC]
RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L]
#
# Internally rewrite <subdomain>.example.co.uk/<page> to /folder/file1.php?show=subdomain&cat=<page>
RewriteCond $1 !^folder/file1\.php$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.co\.uk
RewriteRule ^(.*)$ /folder/file1.php?show=%1&cat=$1 [L]
I also assume that your script can handle requests for robots.txt, sitemap.xml, images, CSS and script files, etc. in each and every subdomain.
Jim