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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
10010110

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

Post 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.
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

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

Post by tsw »

mind pasting your whole .htaccess here

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

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

Post 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
...
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

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

Post 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 ;)
10010110

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

Post 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?
akronim

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

Post by akronim »

same exact thing it' appening to me!
can't figure out how solve it !!! :(
10010110

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

Post 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.
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

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

Post 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)
10010110

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

Post 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)
Locked

Return to “CMSMS Core”