Forum Moderators: phranque

Message Too Old, No Replies

htaccess not working with new host

         

sleepy_az

11:28 pm on Dec 9, 2008 (gmt 0)

10+ Year Member



Our htaccess (below) was working fine until we changed host.

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...

g1smd

11:53 pm on Dec 9, 2008 (gmt 0)

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



Your last rule looks like it is chopped off, you have the Cond line but no Rule.

That last rule looks like a redirect. All of the redirects must be listed before all of the rewrites - that hasn't happened here.

jdMorgan

12:40 am on Dec 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What version of Apache is this new server running?

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

sleepy_az

12:56 am on Dec 10, 2008 (gmt 0)

10+ Year Member



Here is the complete htaccess - I know it's probably very inefficient - though tried my best at the time...

# 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]

jdMorgan

1:37 am on Dec 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AcceptPathInfo? MultiViews? Either one help? (See above questions)

Jim

sleepy_az

1:49 am on Dec 10, 2008 (gmt 0)

10+ Year Member



Its embarrassing - I totally overlooked the fact that the new site is using php5, while the old was php4 - hence register globals was set to off.

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.

jdMorgan

2:12 am on Dec 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's still not clear whether the RewriteCond line shown as the last line of your initial code post is intended to control the RewriteRule that follows it in your second code post or not... It will, but was that the intent?

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