2
votes

I'm having an issue with mod_rewrite that I think might be caused by a global rule in some other config file besides my .htaccess and need to see if there is a way to display all the RewriteRules that are in effect.

Specifically, my issue is http://mydomain.com/pages/test works fine (redirects to pages/index.php), however http://mydomain.com/pages/test-page returns a 404 error. Anything that contains a dash after pages/ breaks. Everything else works. The rewrite rule should be: If the /pages/file.xx is found, display it. Otherwise send it to /pages/index.php

My .htaccess


RewriteEngine On
RewriteBase /pages

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(am-.*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*)$ /pages/$1/ [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-_\/\s]+)/?$ /pages/index.php [L]

EDIT With RewriteLog turned on, I get the following for URL "domain.com/pages/test-string":

xx.xx.xx.xx - - [03/Oct/2012:11:34:15 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] pass through /hsphere/local/home/domain/domain.com/pages/test-string
xx.xx.xx.xx - - [03/Oct/2012:11:34:16 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] pass through /hsphere/local/home/domain/domain.com/splash/test-string

Here is the results for URL "domain.com/pages/test"

xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] rewrite test -> /pages/test/
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] explicitly forcing redirect with http://domain.com/pages/test/
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] trying to replace prefix /hsphere/local/home/domain/domain.com/pages/ with /pages
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] escaping http://domain.com/pages/test/ for redirect
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] redirect to http://domain.com/pages/test/ [REDIRECT/301]
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] rewrite test/ -> /pages/index.php
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] trying to replace prefix /hsphere/local/home/domain/domain.com/pages/ with /pages
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] internal redirect with /pages/index.php [INTERNAL REDIRECT]
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#17c144e0/initial/redir#1] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] pass through /hsphere/local/home/domain/domain.com/pages/index.php
1
RewriteRule . - [L] should be RewriteRule .* - [L] for clarity IMHO. The \s in the last character class should be superfluous as a URL with a literal whitespace character in it should result in a 400 error, also / doesn't need to be escaped in a mod_rewrite regex because it does not use explicit delimiters. I doubt either of those points would fix the problem, just general comments. Where is this .htaccess file located?DaveRandom
this .htaccess file is located in the /pages/ subdirectory. (This is a sub-site of a WordPress site, so possibly the root /.htaccess file is affecting it, however I've tried removing the root /.htaccess and it still had the problem which makes me think the issue is higher up in the httpd.conf or site specific site.conf fileJohn P
Well it seems to me that there is too much logic in the file, for example your first rule asserts that if the file exists it will be served directly, yet several of the following rules still continue to assert that the file does not exist. You could do with removing some of the bloat, I think, it might make the problem easier to see. If removing the .htaccess file in the root does not affect it, it is highly unlikely that there are any other rules playing a part in the problem.DaveRandom
Consider this: pastebin.com/xRVRj4Vt Reduces to this: pastebin.com/JwJigFZUDaveRandom
Dave - Thanks for the help, but I am still getting the same behavior with your modified .htaccessJohn P

1 Answers

0
votes

Add lines for RewriteLog and RewriteLogLevel. I would start with log level 2 or 3 because it can get pretty long.