Forum Moderators: phranque

Message Too Old, No Replies

Redirecting already rewritten URLS

How to use 301 redirectmatch to redirect rewritten URL (mod_rewrite)

         

luksus

11:49 am on Jan 12, 2006 (gmt 0)

10+ Year Member



Hello All!

I got my rewritten URL listed in google, but unfortunately i needed to change them

old url was: mydomain.co.uk/category_name/oldfilename.html

new url is: mydomain.co.uk/category_name/newfilename.html

Have added 301 RedirectMatch:
RedirectMatch 301 /(.*)/oldfilename.html [mydomain.co.uk...]

it works fine but it produces unnecessary string at the end of the URL, i.e.:
this mydomain.co.uk/category_name/oldfilename.html is redirected to:
mydomain.co.uk/category_name/newfilename.html?selcd=category_name

I would appreciate all the suggestions as i have spent few hours trying to get that sorted.

Thanks,
Luke

Here is my whole .htaccess file

AddType application/x-httpd-php .htm .html
Redirect 301 /index.php [mydomain.co.uk...]
RedirectMatch 301 /(.*)/oldfilename.html [mydomain.co.uk...]
rewriteEngine on
RewriteRule (.*).html /index.html?selcd=$1 [L]

jdMorgan

12:46 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to use mod_rewrite to do both functions, rather than using mod_rewrite for one and mod_alias for the other. Do the external redirect first, followed by the internal rewrite.

This will avoid 'exposing' your internal URL-path.

If you use two different modules, then you cannot control the order of execution, since Apache decides which module to run first, and that module will parse your code and execute all the directives it understands, before the other module processes any of the directives that it understands.

In other words, you can control the order of execution only of directives processed by the same module. Apache decides which module's directives are processed first.

This is controlled by the reverse LoadModule order in Apache 1.x, and by a module priority scheme in Apache 2.x, but the effect is the same from the viewpoint of .htaccess directive execution.

Jim

luksus

1:38 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Thans so much.
That was really helpful.

Luke