I'm having the weirdest problem with a previous developer's URL rewrites after moving this custom CMS to a new server. Observe this snippet of the .htaccess file:
RewriteEngine On
# If the URL doesn't end in a slash, redirect them to the equivalent that does (for canonical/SEO purporses)
RewriteCond %{REQUEST_URI} !.*/$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^(health|nutrition|fitness|directory|coupons|download|kids|faq|signup|menu|snp|myaccount|myschool|printmenu)(.*)$ /$1$2/ [R=301,L,QSA,NS]
# Health Pages
RewriteRule ^health/$ health.php [L]
RewriteRule ^health/([^/]+)/$ health.php?title=$1 [L]
RewriteRule ^health/([^/]+)/([^/]+)/$ health_article_details.php?cat=$1&title=$2 [L]
The first part of the Health rewrite:
# Health Pages
RewriteRule ^health/$ health.php [L]
works as expected, but:
RewriteRule ^health/([^/]+)/$ health.php?title=$1 [L]
RewriteRule ^health/([^/]+)/([^/]+)/$ health_article_details.php?cat=$1&title=$2 [L]
don't forward the rest of the URL segment as an argument. I threw a print_r($_REQUEST);
in at the start of health.php and with a URL of http://www.foo.com/health/a/b/
, I get this output:
Array ()
Why is this happening instead of:
Array ( [title] => a )
Any suggestions would be very appreciated!
You put the
print_r($_REQUEST);
in the wrong file. The rewrite that matches that URL gets sent tohealth_article_details.php
.For that URL you should get:
Why you got anything at all I don't know. Possibly health_article_details.php
include()
s health.php.Oddly enough, the rewrites ought never have worked. On advice given by someone in freenode's #httpd channel, I changed the rewrites like so:
Without
QSA
no query strings were being forwarded. I have no idea why this worked in its original context, but as of this moment it no longer matters.