Forum Moderators: phranque

Message Too Old, No Replies

Can't get a redirect 301 to function properly

         

RayTracy

9:06 pm on Aug 19, 2010 (gmt 0)

10+ Year Member



I'm a newbie at fiddling around with .htaccess, so bare with me. :D

I have moved from a static site to a MODx installation, but the site had been up for many years, so a lot of links on the net still points to old documents which no longer exists.

So I tried with redirect 301, like this:

Code:

redirect 301 /english.asp http://www.mysite.se/english.php



but this doesn't work, since it only produces a link like this:

www.mysite.se/english.php?q=english.asp


I guess it has something to do with this line:

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]



but I can't delete it since it is needed for Friendly URLs part.

How can I get around this problem?!?

Cheers
Amrit

jdMorgan

3:49 am on Aug 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do not mix mod_alias directives (like "Redirect") with mod_rewrite directives (like "RewriteRule").

Put the external redirect rewriterule first, and the internal rewrite rewriterule after that.

In general, it is a bad idea to redirect all missing pages, unless the new URL is an exact replacement for each missing page.

You code does not produce links. It redirects and rewrites requests arriving at the server as a result of a browser clicking or a search engine following a link.

If you can better define what you actually want to accomplish, a better answer may be possible. Please remember that we do not know how your site is intended to work...

Jim

RayTracy

4:11 pm on Aug 20, 2010 (gmt 0)

10+ Year Member



Hi jdMorgan.

I am changing a name of an alias from oldname.php, to newname.php, and the content is the exact same. My client wishes this change.

Just changing the alias is of course easy, but a lot of websites points to the oldname.php, and I wish to redirect these to newname.php

I have about 3 pages I need to this with, so I can do it with a PHP script redirect, but I rather not if I can avoid it...

jdMorgan

6:32 pm on Aug 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As stated, do not mix mod_alias "Redirect" and "RedirectMatch" directives with mod_rewrite directives.

Two new example rules to replace your mod_alias "Redirect" directive:

RewriteRule ^english\.asp$ http://www.example.se/english.php [R=301,L]
RewriteRule ^oldname\.asp$ http://www.example.se/newname.php [R=301,L]

Put your rules for the three old URLs ahead of your internal rewrite used for friendly URLs.

See the concurrent thread "Proper Order for htaccess [webmasterworld.com]", for more info on this subject. This will help you avoid some potentially-very-serious self-inflicted problems.

Jim

RayTracy

8:01 pm on Aug 20, 2010 (gmt 0)

10+ Year Member



Thank you so much for helping me. Much appreciated. :-)

I also read everything you wrote in that little tutorial you had wrote, so now I understand exactly why I should be doing what I just did. :-)

And I agree with the others, you could really write a good useful book about this. Talk to the people at sitepoint.com when your script is done... ;)

Sincerly
Amrit