homepage Welcome to WebmasterWorld Guest from 54.167.185.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess 301 redirect help
ergesa




msg:4519363
 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




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

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




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

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




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

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




msg:4519513
 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




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

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




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved