views:

97

answers:

3

I have a script that echoes a meta redirect to a page called account_management.php5, but for some reason it automatically redirects from there to index.php5. My .htaccess file handles a couple of redirects automatically, for example index.html|php5 to the domain root, and that's the only place I can see this problem originating, but I don't understand why. This is my .htaccess file:

RewriteEngine On

#remember to change this to aromaclear
RewriteCond %{HTTP_HOST} !^sinaesthesia\.co.uk$ [NC]
RewriteRule ^(.*)$ http://sinaesthesia.co.uk/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php5|html)\ HTTP
RewriteRule ^(.*)index\.(php5|html)$ /$1 [R=301,L]

#translate any .html ending into .php5
RewriteRule ^(.*)\.html$ /$1\.php5

#change / for ?
RewriteRule ^(.*)\.html/(.*)$ /$1\.html?$2

#strip .html from search res page
RewriteRule ^(.*)search/(.*)$ /$1search_results\.html/search=$2

#translate product details link from search res page
RewriteRule ^products/(.*)/(.*)/(.*)$ /product_details.php5?category=$1&title=$2&id=$3 [L]

#Translate products/psorisis/chamomile-skin-cream-P[x] to productview.php5?id=1
RewriteRule ^products/.*-P([0-9]+) /productview.php5?id=$1 [L]
A: 

Add this just after RewriteEngine on

RewriteLogLevel 9
RewriteLog /tmp/rw.log

Then restart the webserver. It should help you debug the problem.


Edit: Sorry, I didn't notice the .htaccess above. This will only work from the main apache configuration file.

gahooa
Hm, the server is remote, and I have no control over it. I can upload my own log file, but will that log errors without restarting the server?
It acually goas in the .htaccess, so I guess you have access over it. Just modify it to make the logs go somewhere you can access.
Havenard
The `RewriteLogLevel` and `RewriteLog` directive are both not allowed in the .htaccess file. See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
Gumbo
+1  A: 
Havenard
-1 A lot of bad or even wrong recommendations. I don’t even know where to start.
Gumbo
1. Your *Righter* example is wrong: There is no group whose match could be referenced to with `$1`. 2. The QSA flag is not needed as the substitution doesn’t has a query. 3. There are examples where testing the `THE_REQUEST` value is necessary as it holds the orignial HTTP request line while other variables may have already been changed. 4. You don’t need a key to put a value in the query. 5. Why should `.*` be unstable when delimiting the pattern? Not delimiting the pattern would have a complete different meaning.
Gumbo
6. The hyphen does only describe a character range when used in a character class between two characters that are not already describing a character range.
Gumbo
Ha, oh now I'm confused. I am brand new to mod_rewrite, and to regex as a whole. The pattern involving comparing THE_REQUEST and HTTP I copied verbatim from a website on mod_rewrite and it works. It all works as I expect, or it wouldn't be there. All I really need to know is is there anything wrong with the redirect one, that would redirect a page other than index.(html|php5)? I am trying to redirect to a page called account_manangement.html, and instead getting index (or domain root, thanks to my rewriting).
^ the above sounds ignorant - I want to know why this stuff works, of course, I'm not just looking to be spoon-fed answers, but I take what I can get, too ^.^
1. ok, fixed; 2. you don't know that to tell it won't have a query; 3. Testing the THE_REQUEST may be necessary, but thats not one of those cases; 4. yeap, but you do need to format that, and its better to put it in a key, I just gave a good advice;
Havenard
5. .* is unstable because "greedy star" can match some / if user mess around with the url. read the regular expressions expecification; 6. not sure about that, I already have cases where I got to escape the -, otherwise it was giving errors.
Havenard
@Havenard: To 2.: Your *substitution URL* has no query specified. An that’s the decisive factor for whether you need the QSA flag or not. – To 4.: “It won’t work” is not just a good advice for best practice. – To 5.: That’s true, but why does it make the expression unstable? The behavior of the expression is still predictable.
Gumbo
+1  A: 

Egads - my stoopidity knows no bounds! I won't even embarass myself with the details. Sorry, guys!