Welcome to WebmasterWorld Guest from 50.19.53.104

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess 301 redirect help

     

ergesa

1:58 pm on Nov 15, 2012 (gmt 0)



Hi,
I'm trying to redirect old urls of my old web site to new urls to my new web site.
There ara several urls to redirect and I need to redirect them one to one.
My old url is:
http://www.oldsite.com/index.php?page=old-address

And the new url is:
http://www.newsite.com/new-adress


I tried this;
######
RewriteEngine On
RewriteBase /
redirect 301 /index.php?page=old-address http://www.newsite.com/new-adress

######

And this;
######
RewriteEngine On
RewriteBase /
redirect 301 /index.php%3Fpage=old-address http://www.newsite.com/new-adress

######

but it didn't work. Do you have any idea to help me?

Thanks.

phranque

3:13 pm on Nov 15, 2012 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, ergesa!

the Redirect directive (part of the mod_alias apache module) doesn't recognize the query string, which starts after the question mark in the URL.

if your redirect depends on the query string you must use mod_rewrite and examine the %{QUERY_STRING} environment variable using the RewriteCond directive and then redirect using the RewriteRule directive.

there are many examples to study in this forum of Redirect with query string in URL:
http://www.webmasterworld.com/apache/3479175.htm [webmasterworld.com]

lucy24

10:14 pm on Nov 15, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



mod_alias also doesn't recognize RewriteEngine On. That goes with mod_rewrite. So it was wrong before but is about to become right ;)

In any case you don't need the RewriteBase. First because / is the default, and second because the RewriteBase is only used in one situation, and it's a situation that will never occur. (Because you will never allow it to occur. It is within your control.)

What you do need is a rewrite to come after your redirect.* Both will use mod_rewrite and will say RewriteRule, but they will end up in different places.


* Every time I get the capitalization wrong, I promptly receive a reproachful Sticky Mail from You Know Who You Are :P

g1smd

11:25 pm on Nov 15, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



mod_rewrite is the Swiss Army Knife of server configuration tools. You can use a RewriteRule directive to invoke an external redirect or configure it as an internal rewrite.

Once you learn how to use mod_rewrite, you forget that mod_alias and it's very limited functionality in Redirect and RedirectMatch ever existed.

ergesa

11:35 pm on Nov 15, 2012 (gmt 0)



If we talk about the only url I gave before, what is the exact phrase to redirect it using mod_rewrite ?
Sorry about asking this but I'm really not good on this staff.

g1smd

11:58 pm on Nov 15, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You can only improve if you attempt to learn how it works.

Using any one of the previous couple of thousand examples posted in this forum at least have a go. :)

The linked-to example in an earlier post isn't all that different to what you want to do. It's mostly a substitution operation to get the code how you want it.

lucy24

3:27 am on Nov 16, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



There's a complication though. If the original post shows what the URLs really look like, then the old URL is php-plus-query while the new URL is extensionless. Or at least queryless.

So unless the new domain uses static html pages, or there's a CMS that takes care of this stuff, you will also need a rewrite pointing to where the content really lives. This part will happen on the new domain.

AND, if I'm reading all of the above correctly, the new domain will need a supplementary redirect for anyone who rashly types in newdomain.com/index.php?page=long-complicated-query. Or manually changes the bookmark.

"Will y'all stop blathering and just gimme the code?"

Nope. Once in a blue moon someone forgets himself and just spits out the two lines of code instead of the 20-line explanation, but you can't count on it.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month