Welcome to WebmasterWorld Guest from 54.167.22.37

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Single file redirect

     

beachlover

3:37 pm on Jun 3, 2010 (gmt 0)

10+ Year Member



Well, I'm a bit lost here as this code is not working:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^main.php?section=oldpage$ /newpage/ [R=301,L]

Forgive my blindness but I stared at this piece of code for hours now without getting it...

g1smd

6:45 pm on Jun 3, 2010 (gmt 0)

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



What is it meant to to do?

RewriteRule can only see the path part of the URL.

You will therefore need a preceding RewriteCond looking at QUERY_STRING.

The redirect target should include the protocol and domain name.

beachlover

8:50 pm on Jun 3, 2010 (gmt 0)

10+ Year Member



Damn, I knew I was way off here. So thanks for your heads up.

I guess this will work then:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{QUERY_STRING} ^section=(oldpage*)$
RewriteRule main.php ht tp://www.domain.com/newpage/ [L,R=301]

jdMorgan

9:14 pm on Jun 3, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The rule as written will 'carry forward' the originally-requested query string. Is that what you want to do?

Again, what exactly is this rule meant to do? What is the (full) requested URI-path to be redirected, and what is the full URI to be redirected to?

"It will work" is only about 10% of the way to "It will work properly with no unintended side effects," and that is not good enough; For optimal results, nail down your requirements firmly before we start coding.

Jim

beachlover

9:42 pm on Jun 3, 2010 (gmt 0)

10+ Year Member



Thanks for your response.

Basically I want to redirect the old php-file to a new file (which is now in a directory-based CMS):

ht tp://domain.com/main.php?section=oldpage

to

ht tp://domain.com/newpage/

jdMorgan

10:01 pm on Jun 3, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



In that case, you "bascially" need to clear the query string using the "?" operator on the substitution URL:

Options +FollowSymLinks
RewriteEngine On
#
RewriteCond %{QUERY_STRING} ^section=oldpage-string$
RewriteRule ^main\.php$ http://www.example.com/newpage/? [L,R=301]

Note othe minor corrections to literal query string value, anchoring, and literal-character escaping in rule pattern.

You can use the mod_rewrite documentation at apache.org to determine if this is exactly what you want to do.

Jim

beachlover

10:07 pm on Jun 3, 2010 (gmt 0)

10+ Year Member



Thanks Jim, works like a charm.

g1smd

10:47 pm on Jun 3, 2010 (gmt 0)

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



What happens if you ask for the non-www version of the old URL, and/or if you append extra parameters?

Does it then still do exactly what you want?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month