Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite problem

redirecting old .asp pages

         

pdesigns

3:05 am on Aug 15, 2006 (gmt 0)

10+ Year Member



I've recently switched over to a linux server running Apache from a Windows server and had been using ASP.

I have just gotten familiar with mod_rewrite and wrote a nice rule as follows:


RewriteEngine on
RewriteRule ^page/(.*)?$ index.php?page=$1 [L]

The above rule will allow pages going from www.mysite.com/page/the_page to www.mysite.com/index.php?page=the_page

However, since I had been using .asp pages in the form of module.asp?page=the_page they have been archived by search engines. I want to redirect any of those page requests to the same www.mysite.com/page/the_page format.

I tried using the below code:


RewriteRule ^module.asp\?page=(.*)$ /page/$1 [R=301]

But it doesn't seem to work. So my question is, what is wrong with my rule, am I missing something? Hope someone here can help me.

Thanks in advance.

jdMorgan

3:16 am on Aug 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Query strings are handled separately:

RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteRule ^module\.asp$ http://www.example.com/page/%1 [R=301,L]

Jim

[edited by: jdMorgan at 3:16 am (utc) on Aug. 15, 2006]

pdesigns

3:23 am on Aug 15, 2006 (gmt 0)

10+ Year Member



Thanks for your reply. It works, but not exactly what I want it to do. When using what you provided me the page redirects to the following:
www.mysite.com/page/the_page?page=the_page

For some reason it is getting?page=the_page along with it. Any more help would be greatly appreciated. Thanks again.

jdMorgan

12:12 pm on Aug 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I forget to clear the query string more often than not...


RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteRule ^module\.asp$ http://www.example.com/page/[b]%1?[/b] [R=301,L]

Jim

pdesigns

1:59 pm on Aug 15, 2006 (gmt 0)

10+ Year Member



It works! Thanks a lot, I really appreciate it. I'm not suprised why you're moderator of this forums =)