Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite problem

         

mvdbrand

12:34 pm on Mar 9, 2009 (gmt 0)

10+ Year Member



This is my .htaccess:


redirect 301 /routebeschrijving.html http://www.web-site.nl/locatie/routebeschrijving.html

ErrorDocument 404 404.html

RewriteEngine on

RewriteCond %{HTTP_HOST} ^web-site\.nl

RewriteRule ^(.*)$ http://www.web-site.nl/$1 [R=permanent,L]

RewriteRule ^index.html$ / [L,R=301]

RewriteRule ^(.*)/(.*).html$ index.php?directory=$1&filename=$2.html [L]

RewriteRule ^(.*).html$ index.php?filename=$1.html [L]

if I open [web-site.nl...] in the browser it redirects to: [web-site.nl...]

but I want it to redirect to: [web-site.nl...]

I don't understand where the querystring is coming from.

Can somebody help me?

Thanx in advandce,

Marten

g1smd

8:10 pm on Mar 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There are other issues here.

If you use

RewriteRule
, then do not use
Redirect
in the same .htaccess file - use
RewriteRule
for all the rules.

ErrorDocument 404 404.html
- use need to add the path (i.e.
[b]/[/b]404.html
here) in front of the URL.

Note that

^(.*)$
simplifies to
(.*)
here.

RewriteRule ^index.html$ / [L,R=301]
- this rule could lead to infinite looping when a request for / is internally rewritten to the /index.html filename because that matches this rule again. Additionally it redirects all index files in all folders to the root of the site, and it does not redirect to the canonical domain. You are better off using the longer code posted in several threads in recent days, as that preserves the requested folder name in the redirect, and fixes the canonical domain at the same time for those requests.

RewriteRule ^(.*)/(.*).html$ index.php?directory=$1&filename=$2.html [L]
- Using
(.*)
twice in the same rule is very inefficient. There's many examples of better patterns to use, several posted just this last weekend.

Finally, you can clear a query string in a redirect, by adding a question mark to the end of the target URL.

Note that redirects should contain the canonical domain in the target URL, and

[R=301,L]
at the end. Omitting the domain name will lead to some requests having to go through a redirection chain to get to the final URL- and that is not a good thing.

You must put the index redirect before the general non-www to www redirect, otherwise you'll also end up with another redirection chain.

A rewrite must not contain a domain name and should always end with

[L]
unless you want 'weird effects'.