Forum Moderators: phranque
The problem now is that while the 'add www' and 'add/' rules work - for some reason the URL variables are not being passed on.
For example - if I go to www.mysite.com/variableone/ - it loads the index.php page alright, but I can't access the variable.
Hope this makes sense.
Any ideas what to look for? How could changing host create this problem?
-------------
# Enable mod_rewrite, start rewrite engine
Options +FollowSymlinks
RewriteEngine on
#
php_flag session.use_trans_sid off
# add www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ [%{HTTP_HOST}...] [R=301,L]
# add /
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ [%{HTTP_HOST}...] [R=301,L]
# dont process non php pages
RewriteRule \.(css¦jpe?g¦gif¦png)$ - [L]
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^([a-zA-Z0-9\-]+)/$ /index.php?MS_KW=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ /index.php?MS_KW=$1&FLAG=$2 [QSA,L]
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php(.*)\ HTTP/ [NC]
-----------
Thanks for your help...
If it's Apache 2.x, then try disabling AcceptPathInfo. If Apache 1.x, then try disabling MultiViews.
Also, I suggest you look into using the [NC] flag on the two internal rewrites. It would speed up the sub-pattern match(es) by 30% by allowing you to use "[a-z0-9\-]" in a case-insensitive match, rather than "[a-zA-Z0-9\-]"
Please do post that final redirect if you are still using it. There's a real time-waster in its RewriteCond, but a good fix can't be confidently suggested without seeing the rule itself.
Jim
# Enable mod_rewrite, start rewrite engine
Options +FollowSymlinks
RewriteEngine on
#
php_flag session.use_trans_sid off
# add www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ [%{HTTP_HOST}...] [R=301,L]
# add /
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ [%{HTTP_HOST}...] [R=301,L]
# dont process non php pages
RewriteRule \.(css¦jpe?g¦gif¦png)$ - [L]
# .co.nz to .com
RewriteCond %{HTTP_HOST} ^www\.site\.co.nz
RewriteRule (.*) [mainsite.com...] [R=301,L]
# other URL to .com
RewriteCond %{HTTP_HOST} ^www\.url\.co.nz
RewriteRule (.*) [mainsite.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.url\.com.au
RewriteRule (.*) [mainsite.com...] [R=301,L]
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^([a-zA-Z0-9\-]+)/$ /index.php?MS_KW=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ /index.php?MS_KW=$1&FLAG=$2 [QSA,L]
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php(.*)\ HTTP/ [NC]
## homepage
RewriteRule ^index\.php(.*)$ [mainsite.com...] [R=301,L]
## subpages
RewriteRule ^Explore-Travel-Passes.php$ /new-zealand-bus-travel/ [R=301,L]
RewriteRule ^new-zealand-travel.php$ /new-zealand-bus-travel/ [R=301,L]
RewriteRule ^north-island-travel.php$ /new-zealand-bus-travel/ [R=301,L]
RewriteRule ^south-island-travel.php$ /new-zealand-bus-travel/ [R=301,L]
# From WebMasterTools
RewriteRule ^cityTour/sitemap.php$ [mainsite.com...] [R=301,L]
RewriteRule ^Travel-Deals-More.php$ [mainsite.com...] [R=301,L]
RewriteCond %{QUERY_STRING} flag=*
RewriteRule ^Travel-Specials.php$ [mainsite.com...] [R=301,L]
# pdf
RewriteRule ^fpGerman.pdf$ /busrundreisen-in-neuseeland/? [R=301,L]
RewriteRule ^info.pdf$ [mainsite.com...] [R=301,L]
# xls
RewriteRule ^Autumn08a.xls$ [mainsite.com...] [R=301,L]
RewriteRule ^Spring08.xls$ [mainsite.com...] [R=301,L]
# NoticeBoard with variable
RewriteCond %{QUERY_STRING} num=*
RewriteRule ^Travel-Comments-View.php$ /new-zealand-backpackers/? [R=301,L]
# NoticeBoard with no variable
RewriteRule ^Travel-Comments.php$ /new-zealand-backpackers/ [R=301,L]
I've set them to ON in the htaccess - until I have time to rewrite the code so that they can be OFF (or make sure there is no security issues - another chance to learn something new...).
BTW: now that I've posted the existing htaccess above - any major errors?
Thanks so much for all your help.
In all cases where [R=301,L] is used, best practices dictate that the substitution URL in the RewriteRule should include the protocol and the hostname. Some of your rules do, and some don't.
Typically, this isn't a problem. But if you change hosts and the new host defines a different canonical ServerName (e.g. "www" vs. "non-www") and sets UseCanonicalName to 'on' you can end up with unexpected redirects and even 'infinite' redirection loops.
Jim