Forum Moderators: phranque
I have inherited some code that works perfectly in one place but not so well when i move it elsewhere and try and use it again...
I have a site working perfectly well for a few years , the guy who created it set it all up with nice clean url's via mod rewrite. I am cloning the site and re tasking it for another purpose and to this end I have moved the entire thing lock stock and barrel to a new server. The first major problem I have encountered is of course with the mod rewrite.
I have the original settings from the working website and have simply altered them to include the new url im using.
The original working code (from virtualminapache settings)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,QSA,L]
RewriteRule ^/(assets¦admincp)/(.*) - [L]
RewriteRule ^/(.*)([^/])$ /$1$2/ [R=301]
RewriteRule ^/(.*)$ /index.php [QSA] I stress again this is working fine on my existing website. It's running on the same Centos with the same modules active (if that makes any difference)..
The site I am trying to get it working on is http://www.example.co.uk and these are the changes i have made to get it working, sadly this ends in a redirect loop.
Entered into a httpd.conf file.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^http://www.example\.co\.uk$
RewriteRule ^(.*)$ http://www.example.co.uk$1 [R=301,QSA,L]
RewriteRule ^/(assets¦admincp)/(.*) - [L]
RewriteRule ^/(.*)([^/])$ /$1$2/ [R=301]
RewriteRule ^/(.*)$ /index.php [QSA] (UseCanonicalName OFF) is already set globally. Please note that on the rewriteCond line i have added the http:// on line three as without it , it appears to do nothing at all.
Assuming that since it all works fine on another box with a different URL and that the code is ok, are there any other settings on the box i should be looking at to get this to work.
Spent 20 of the last 24 hours working on this and im just going around in circles now with no new ideas to try. Any advice/ideas/assistance anyone is able to lend would be massively appreciated.
Fingers crossed I have made a simple schoolboy error somebody is going to spot and point out! If of course there is any further information I need to post to help solve this problem - please do say so and I'll get right on it!
[edited by: jdMorgan at 11:47 pm (utc) on Aug. 12, 2009]
[edit reason] example.co.uk [/edit]
That rule should only be invoked if an incorrect subdomain (but one which does resolve to your server in DNS) is requested. Since %{HTTP_HOST} will never contain a protocol (HTTP), if the rule really doesn't work as posted below, then something else is *severely* wrong with your server.
First, clean up what you've got:
RewriteEngine on
#
# Externally redirect non-canonical host requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.co\.uk)?$
RewriteRule ^/(.*)$ http://www.example.co.uk/$1 [R=301,L]
#
# Skip all following rules if assets or admin directory URLs requested
RewriteRule ^/(assets¦admincp)/ - [L]
#
# Externally redirect to add missing trailing slashes to all URLs
RewriteRule ^/(.*[^/])$ http://www.example.co.uk/$1/ [R=301,L]
#
# Internally rewrite *all* requested URLs to index.php
RewriteRule ^/(.*)$ /index.php [L]
Having verified that, check the transactions between your browser and your server using an HTTP headers Checker such as Live HTTP Headers for Firefox/Mozilla, and review your server error log for hints at what things are going wrong (and when).
Be sure to change all broken pipe "¦" characters you see posted here to solid pipes before use; Posting on this forum modifies the pipe characters.
Also be sure to restart your server and completely flush (delete) your browser cache after any change to your server-side code.
Jim