Forum Moderators: phranque

Message Too Old, No Replies

Probably just a missing backslash but I can't see it!

         

internetheaven

8:24 pm on Aug 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Been a day of full stops in the wrong place and missing backslashes! Now I have a mod_rewrite not working. Anyone see what's missing?

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:

[subdomain.example.co.uk...]

to

http://www.example.co.uk/folder/file1.php?show=subdomain&cat=page

Thanks
Mike

jdMorgan

11:25 pm on Aug 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There *is* a missing backslash in example\.co.uk, but that's not a 'fatal' problem.

Hoever, what is the purpose of this line?


RewriteCond %1<>%3 !^(.*)<>\1$ [NC]

I ask because:

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

internetheaven

3:59 pm on Aug 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Like I said, I just want:

[subdomain.example.co.uk...]

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.

g1smd

7:53 pm on Aug 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Both of those are presented as "URL"s.

Which one is a URL used out on the web, and which one is a filepath used inside a server (and therefore doesn't need a domain name)?

jdMorgan

2:56 am on Aug 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, you're apparently copying code without understanding it. Not a good plan.

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 assumed that this code will be located in example.com/.htaccess

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

internetheaven

12:32 pm on Aug 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks.