views:

23

answers:

1

My .htaccess file is:

Redirect 301    http://domain.com/news/articles?dtMain_start=150    http://domain.com/news/articles
Redirect 301    http://domain.com/news/articles?dtMain_start=160    http://domain.com/news/articles
Redirect 301    http://domain.com/news/articles?dtMain_start=170    http://domain.com/news/articles
# 
RewriteEngine On
RewriteBase /

# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

I also have to incorporate the following rule

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.co.uk/$1 [R=301,L]

I cannot get them to work together... can anyone help...

I tried just stacking the Redirects before the RewriteCond and I get this... http://www.domain.com/news/articles?q=news/articles?dbMain_start=150
ie http://domain.com/newpage?q=oldpage

Okay Mod_Alias and Mod_Rewrite don't like each other.

Can I write something like:

RewriteCond %{REQUEST_QUERY_STRING} ^.*&bodgeredirect=true$
RewriteRule ^(.*)&bodgeredirect=true$ index.php?q=$1 [L,QSA]
A: 

First of all: There is not mod_redirect. Redirect is a directive of mod_alias.

And the Redirect directive, like any other directive of mod_alias, does only work with the URL path. So your Redirect directives won’t work as expected. Use mod_rewrite equivalents instead:

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

RewriteCond %{QUERY_STRING} ^dtMain_start=(150|160|170)$
RewriteRule ^news/articles$ /news/articles? [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

In general it is not a good idea to mix mod_alias and mod_rewrite if the patterns coincide with each other.

Gumbo
Thanks. My bad on misunderstanding the source of Redirect. I have been given 500 or so Redirects in the above format from an SEO agency. I realised my problem was there were extra spaces and illegal characters instead of being URL encoded. Can I just dump all the redirects in before my RewriteConds?
Simon
@Simon: Since the mentioned `Redirect` directives don’t work anyway, yes.
Gumbo
@Simon: Oh, and also dump your SEO agency. ;)
Gumbo
@Gumbo I wish I could! Can you see the update on my original question? Mod_Rewrite is screwing up the Redirects... can I bypass Mod_Rewrite if a Redirect takes place? Thanks.
Simon
@Simon: No, I’m afraid that’s not possible. That means it’s a bad idea to mix mod_alias with mod_rewrite.
Gumbo
Okay will find another solution. Thanks.
Simon
Actually change of plan. Can I form a condition on http code 301?
Simon
@Simon: mod_rewrite react on requests and not on responses. So you can only rewrite/redirect requests and not responses. And 301 is a response status code.
Gumbo
Okay. It seems my suggestion is not possible.
Simon