Forum Moderators: phranque

Message Too Old, No Replies

URL redirect with wildcard to subdir

         

br212

9:22 am on May 8, 2009 (gmt 0)

10+ Year Member



I would like to redirect (permanent 301) all incoming request like:

http://www.example.com/modules.php%C2?name=NukeC
http://www.example.com/modules.php?name=Forums
http://www.example.com/modules.php?name=Forums&file=posting

(So everything that ends with: modules.php*)

to

http://www.example.com/subdir

Is there a way to do so with htaccess? From subdir to subdir i do understand, but from wildcard to one specific subdir.... i dont have a clue. :-(

Already thanks for any help!

[edited by: jdMorgan at 1:57 pm (utc) on May 8, 2009]
[edit reason] example.com [/edit]

jdMorgan

2:00 pm on May 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This can easily be done with .htaccess using Apache mod_rewrite.

Please see the resources cited in our Apache Fourm Charter [webmasterworld.com] to get started.

Our Apache Forum Library [webmasterworld.com] also contains several useful threads and tutorials.

Jim

br212

8:02 pm on May 9, 2009 (gmt 0)

10+ Year Member



OK, i figured out the wildcard thing.

The thing that i still can't get to work is that i want them forwarded to a directory but not append the portion after modules.php to the new url. Just go to subdir, and thats it.

What i put in:

RewriteRule ^modules.php http://www.example.com/subdir/ [R=301,L]

Now:

http://www.example.com/modules.php?name=Forums&file=posting

goes to

http://www.example.com/subdir/?name=Forums&file=posting

instead of

http://www.example.com/subdir/

anybody?

g1smd

10:57 pm on May 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add a question mark to the target URL to clear the query string.

br212

11:08 pm on May 9, 2009 (gmt 0)

10+ Year Member



OK, thanks for your help. Thats did the trick!

RewriteRule ^modules.php http://www.example.com/subdir/? [R=301,L]