Welcome to WebmasterWorld Guest from 52.91.39.106

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

.htaccess, 301 redirects, and Query Strings

I need a 404 redirect which retains a query string

     
9:33 am on Aug 21, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 8, 2002
posts:63
votes: 0


Some time ago I moved my PHP forum from one directory to another.

I'm currently trying to construct a redirect 301 RewriteRule which will convert requests for any file in /forums/ to requests for the same file in the /forum/ directory. However, since the forum is dynamic PHP and using query strings I need the rule to retain the query.

I've tried rules such as:

RewriteRule /forums(.*)$ [mysite.com...]

and

RewriteCond %{REQUEST_URI} ^/forums/$ [NC]
RewriteCond %{QUERY_STRING} ^(.*)$
rewriterule ^(.*)$ [mysite.com...] [R=301,L]

but they don't work. The closest thing that I've got to it so far is:

RedirectMatch permanent /forums(/)? [mysite.com...]

but of course all query string info is lost.

Can someone (Jim *gggg*) suggest a solution, please?

Thanks in advance.

10:04 am on Aug 21, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:July 28, 2000
posts:580
votes: 0


Try

RewriteBase /forums/
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]

These statements need to be in the .htaccess file in the /forums directory

10:21 am on Aug 21, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 8, 2002
posts:63
votes: 0


Thanks, but that doesn't quite work as expected...

A request for...

[mysite.com...]

results in (once I'd removed the rule)...

[mysite.com...]

It also affected all other pages. :-(

1:31 pm on Aug 21, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 0


Try this:


RewriteCond %{REQUEST_URI} ^/forums/
RewriteRule ^(.*)$ http://www.mysite.com/forum/$1 [R=301,L]
1:43 pm on Aug 21, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 0


Now wait a minute...

I know the code that I just gave is wrong, so don't even try it.

Try this:


RewriteRule ^/forums(.*) /forum$1 [R=301,L]
1:53 pm on Aug 21, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 0


Third time's the charm, right?

Try this one instead:


RewriteRule ^/forums(.*) http://www.mysite.com/forum$1 [R=301,L]
1:59 pm on Aug 21, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 8, 2002
posts:63
votes: 0


Almost perfect. Removal of the first slash was all that was needed!

The solution was:

RewriteRule ^forums(.*) /forum$1 [R=301,L]

Thank you for your help! :-D

2:14 pm on Aug 21, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 0


Slash, no slash, whatever. Close enough. LOL

Glad I could help.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members