Forum Moderators: phranque

Message Too Old, No Replies

.htaccess, 301 redirects, and Query Strings

I need a 404 redirect which retains a query string

         

Red5

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

10+ Year Member



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.

mark_roach

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

10+ Year Member



Try

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

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

Red5

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

10+ Year Member



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. :-(

closed

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

10+ Year Member



Try this:


RewriteCond %{REQUEST_URI} ^/forums/
RewriteRule ^(.*)$ http://www.mysite.com/forum/$1 [R=301,L]

closed

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

10+ Year Member



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]

closed

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

10+ Year Member



Third time's the charm, right?

Try this one instead:


RewriteRule ^/forums(.*) http://www.mysite.com/forum$1 [R=301,L]

Red5

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

10+ Year Member



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

closed

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

10+ Year Member



Slash, no slash, whatever. Close enough. LOL

Glad I could help.