Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite with Query String

redirecting old pages to new url with 301 redirect

         

prosam

4:12 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



Hi Guys,
My first post here WebmasterWorld. Seems like a great community I will have fun being part of. On to my issue.

I'm at a loss here trying to figure this out. Seems very complicated.

I'm trying to get this :
mydomain.com/index.php?page=arts-entertainment

to redirect to
mydomain.com/arts-culture.html

I have this so far but it's not working, I'm not sure what I'm doing wrong.

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^page\=arts\-entertainment$
RewriteRule ^$ /arts\-culture.html [R=301,L]

Thanks in advance!

jdMorgan

6:11 pm on Mar 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to include "index\.php" in the RewriteRule pattern, if that's the URL-path you want to redirect.

Also, you don't need to escape those two characters in the query string. In this context, they're both taken as literals.

Other than that, please be a bit more descriptive; We assume that you wouldn't be posting, except that "it doesn't work," so that statement tells us nothing. What URL did you use to test? What was the result? How did the result differ from your expectations? Anything in the server error log?

Jim

prosam

6:44 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



Hi Jim,
Thanks for your help.

ok, this is the problem.
We rebuilt the site and the previous site had pretty good ranking on some of the pages so we don't want to lose them.

So the following link:
valleyvisitor dot com/index.php?page=arts-entertainment

Should now be going to:
valleyvisitor dot com/arts-culture.html

There is no index.php or index file associated with the sub-pages on the new site. Am I going about this the wrong way?

If you enter the old url you are redirected to the homepage. The new site is built using typolight which has internal error page handling and we've also added a 404 on the server that redirects to the homepage.

I'm not sure about the error logs.

Your help is very much appreciated.

g1smd

8:44 pm on Mar 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



*** There is no index.php or index file associated with the sub-pages on the new site. ***

There doesn't need to be. You are taking a URL request, examining the parts of that requested URL, and making a decision to redirect to another URL. That is, filenames on the server are irrelevant; a redirect is issued by the server without any reference to any files on the server. It is dealing only with URLs not files and content.

*** we've also added a 404 on the server that redirects to the homepage ***

This statement troubles me.

A 404 status code is an error code, not a redirect. If the URL really is returning a redirect status code (such as 301, 302, or 307) in the HTTP header then it isn't a 404 page at all - despite what the actual textual content that the user sees, actually says.

If the URL the user sees in the browser address bar is changed as the 404 page is served, then that does not look like a good situation at all.

On the other hand, if it is returning a 404 status in the HTTP header then it is a true 404 page, but I am very wary of showing the home page content as a 404 error page. It can lead to other issues.

prosam

9:07 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



Thanks for your help Jim,
I'm happy to announce that I found the solution at this blog:

[seoverflow.com...]

This is what it looks like now:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^page\=arts-entertainment$
RewriteRule ^index\.php$ [mydomain.com...] [R=301,L]

g1smd

9:30 pm on Mar 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That looks good, but you don't need the RewriteBase line at all.