0

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!

0

You put the print_r($_REQUEST); in the wrong file. The rewrite that matches that URL gets sent to health_article_details.php.

For that URL you should get:

Array ( [cat] => a, [title] => b )

Why you got anything at all I don't know. Possibly health_article_details.php include()s health.php.

  • I suspect you're misinterpreting the rewrites, as the system works fine on the origin server, and health_article_details.php isn't being touched at all. – Sudowned Feb 5 '13 at 18:56
  • Maybe I am... but these rules are not complex so I think it unlikely. Maybe there are more rewrites or other config that's not in your question that affects the URL or maybe you pasted the wrong URL. I don't understand how /health/a/b/ could possible match ^health/$ or ^health/([^/]+)/$ without something mangling it first. – Ladadadada Feb 6 '13 at 10:10
0

Oddly enough, the rewrites ought never have worked. On advice given by someone in freenode's #httpd channel, I changed the rewrites like so:

# Health Pages
RewriteRule ^health/$ health.php [L,QSA]
RewriteRule ^health/([^/]+)/$ health.php?title=$1 [L,QSA]
RewriteRule ^health/([^/]+)/([^/]+)/$ health_article_details.php?cat=$1&title=$2 [L,QSA]

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.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.