Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule help needed

ErrorDocument no longer works

         

NeuralClone

9:23 pm on Jun 3, 2005 (gmt 0)

10+ Year Member



I'm currently using mod_rewrite to handle links on my website.

My URLs look like this:
[domain.com...] (optional query string)

I'm translating the URLs to this format:
[domain.com...]

Here's the relevant portion of my .htaccess file:

Options -Indexes +FollowSymLinks

ErrorDocument 400 /html/lang/errors/400.html
ErrorDocument 403 /html/lang/errors/403.html
ErrorDocument 404 /html/lang/errors/404.html
ErrorDocument 500 /html/lang/errors/500.html
ErrorDocument 502 /html/lang/errors/502.html

RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteCond %{REQUEST_URI} ^($¦/.*$)
RewriteRule ^.* http://www.domain.com%1 [R=permanent,L]

RewriteRule ^html/(eng¦fre)/([A-Za-z0-9]+)(/[A-Za-z0-9]+)?(/[0-9]+)?(\.html)+(\?.*)?$ /html/index.php?lang=$1&cat=$2&page=$3&id=$4&query=$6

Everything seems to be working fine. So what's the problem?

This rewrite rule seems to have disabled ErrorDocuments. Is there something that I'm missing that could be causing this? Or, is there something in my current htaccess file that's preventing ErrorDocument from working? Help!

Thanks in advance!

jdMorgan

10:24 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



NeuralClone:

Welcome to WebmasterWorld!

This line is probably incorrect.


RewriteCond %{REQUEST_URI} ^($¦/.*$)

When combined with the following rule, the result is to rewrite all requests, including those for error documents.

The same is true for the second RewriteRule. A request for "/html/<lang>/errors/400.html" will be rewritten to "/html/index.php?lang=<lang>&cat=errors&page=400&id=&query="

Your patterns are too ambiguous, or necessary exception cases are not handled.

You should decide exactly which pages you do and do not wish to rewrite, and modify the RewriteConds and RewriteRules as needed.

Jim

NeuralClone

10:58 pm on Jun 3, 2005 (gmt 0)

10+ Year Member



Thank you VERY much, jdMorgan!

Removing the line

RewriteCond %{REQUEST_URI} ^($¦/.*$)

fixed the ErrorDocument issues I was having. As for the other rewrite rule, that's exactly what I want it to do.

Thanks again! :)

jdMorgan

11:22 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suspect you'll be happier if you change the first rule to:

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} .
RewriteRule (.*) http://www.example.com/$1 [R=permanent,L]

As it is, any requests for pages in the non-www domain will be redirected to the home page of the www domain, which may cause problems with your search engine rankings. Furthermore, requests on any port except for port 80 would make the rule fail.

Jim

NeuralClone

3:51 am on Jun 4, 2005 (gmt 0)

10+ Year Member



^

Thank you! :D