Page 1 of 1

301 redirect of renamed or non-existing pages... how to?

Posted: Sat Sep 16, 2006 4:49 pm
by 10010110
OK, I've searched the forum but haven't found an answer to that specific question (most of them are just about pretty URLS):

I've implemented an existing website into this great CMS and activated SE friendly URLs. So far so good.
However, there were pages with underscore (e.g. downloads_page.php) which I changed to a regular "minus" (downloads-page.php) for the reason of improved SE friendlyness. Now I need to redirect all pages that had this underscore (or aren't existing anmore) to the appropriate pages with "minus" (or the index page).
Usually I would use

Code: Select all

Redirect 301 /downloads_page.php http://sitename.com/downloads-page.php
However, due to the internal pretty URL rewrite rule the result in the browser when typing the old URL is something like this:

Code: Select all

http://sitename.com/downloads-page.php?page=downloads_page.php
which gives me a 404, of course.

How would I have to change the htaccess file that it redirects to the new pretty URL (i.e. without the parameters)?

I appreciate your help and patience.

Re: 301 redirect of renamed or non-existing pages... how to?

Posted: Sat Sep 16, 2006 6:26 pm
by tsw
mind pasting your whole .htaccess here

iirc you need [RL] at the end so that processing stops at that rule...

Re: 301 redirect of renamed or non-existing pages... how to?

Posted: Sat Sep 16, 2006 7:35 pm
by 10010110
No, I don't mind...  :)

Code: Select all

#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off

# Make sure you have Options FollowSymLinks
# and Allow on
RewriteEngine On

# that one is enabling .htm extensions
RewriteRule (.*).htm$ /$1.php

#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

Redirect permanent /about.php http://www.escortbooks.com/about.php
Redirect permanent /downloads_page.php http://www.exoticpublishing.com/downloads-page.php
...
...
...
This is actually just the default htaccess file that came with the CMS and I added a rule so people can either use .php or .htm as extension (just works with files in the root directory, though). And then I  copied the redirect rules from an old htaccess that has been there before (where it worked).
The old htaccess looked like this:

Code: Select all

RewriteEngine on
RewriteBase /
RewriteRule ^contentid([^.]+).*$ show.php?contentid=$1 [T=application/x-httpd-php]
RewriteRule ^categoryid([^.]+).*$ showcategory.php?categoryid=$1  [T=application/x-httpd-php]

Redirect permanent /about.php http://www.escortbooks.com/about.php
...

Re: 301 redirect of renamed or non-existing pages... how to?

Posted: Sat Sep 16, 2006 9:17 pm
by tsw
yep you want to move your own rules before cmsms rules so that those get processed before cmsms rules get there and add [RL] after the rules

see http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html (very hard to understand first time ;)

Re: 301 redirect of renamed or non-existing pages... how to?

Posted: Sun Sep 17, 2006 5:32 pm
by 10010110
Hm, sorry, I'm proabably just too stupid for mod_rewrite but if I move the redirect rules to the top and apply the [RL] flag after any rule (like this: Redirect permanent /about.php http:/ /escortbooks.com/about.php [RL]) it gives me an internal (500) error. And with the redirects on top and no [RL] flag it's not changing the way it's currently redirected/rewritten...  ???
In the old htaccess file it used to work without the [RL] flag too...

Or am I just not applying it correctly?

Re: 301 redirect of renamed or non-existing pages... how to?

Posted: Mon Sep 18, 2006 10:43 am
by akronim
same exact thing it' appening to me!
can't figure out how solve it !!! :(

Re: 301 redirect of renamed or non-existing pages... how to?

Posted: Sun Sep 24, 2006 10:10 am
by 10010110
So, ain't there anybody that is able to help with this? ???
The developers should know how it works. Can this probably be added to the documentation as there are apparently more people interested in a solution...?  :-\

I appreciate any help. Thanks.

Re: 301 redirect of renamed or non-existing pages... how to?

Posted: Sun Sep 24, 2006 2:49 pm
by tsw
ok, A bit googling reveals that

Code: Select all

redirect 301 / http://www.somedomain.com/ 
works ONLY if the target is on another server...

Code: Select all

RewriteEngine On

RewriteRule ^test\.php$ http://www.domain.tld/home/ [R=301,L]

#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

works here.

note that you need to escape all dots as they have special meaning in regular expressions. [R=301,L] means redirect with 301 and stop do it now (dont process any more rules)

Re: 301 redirect of renamed or non-existing pages... how to?

Posted: Mon Sep 25, 2006 7:32 pm
by 10010110
Hmm, my googling (and/or experience) revealed that it used to work before, even if it was the same server.

But anyway, it's woking now!!  :D

Thanks a lot. You da man! 8)