views:

82

answers:

1

I am trying to make a sitewide 301 redirect for a site with around 400 pages but also have a subset of about 10 individual pages that don't follow the sitewide redirect and should point somewhere else.

Any ideas how to format such redirect rules so the sitewide redirect doesnt conflict with the subset pages redirect?

I am starting with the sitewide redirect rule as:

Options +FollowSymLinks RewriteEngine on RewriteRule (.*) http://www.name.com/$1 [R=301,L]

A: 

The rewrite rules are parsed in the order they are written, so the order you list them also defines the priority. Given that, you should first match the request URI with the 10 individual pages and return the redirection accordingly, and then define the sitewide redirection.

If the 10 individual pages have a single target URL, the match rule may be one, otherwise you should do a single redirection per each request URI.

Take care to use the [L] flag for the first redirections, to tell the server to exit the routine if the rule is matched, and I would also suggest to add the line

RewriteBase /

which is pivotal for some Apache versions, in which the omission of this line may cause a http bad conf error.

Options +FollowSymLinks

#switch on the rewrite engine:
RewriteEngine On
RewriteBase /

#rules for the individual redirections:
RewriteRule http://example.com/myUrl-1 http://www.example.org/new-1 [R=301,L]
RewriteRule http://example.com/myUrl-4 http://www.example.org/new-2 [R=301,L]
RewriteRule http://example.com/myUrl-3 http://www.example.org/new-3 [R=301,L]
#...and so on

#sitewide redirection rule:
RewriteRule (.*) http://www.example.org/$1 [R=301]
Emanuele Del Grande