Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite problem

         

kiransarv

10:14 am on Oct 22, 2008 (gmt 0)

10+ Year Member



I want to redirect url's of pattern /redirect?q=(.*)&url=(.*) to the url.

But it is giving error, "The requested URL /redirecturl was not found on this server".

I have this piece of code in my httpd.conf

ReWriteRule ^/redirecturl?q=(.*)&url=(.*)$ $2 [R=301,L]

Is there any thing i need to add..or it this wrong?

jdMorgan

1:07 pm on Oct 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

RewriteCond %{QUERY_STRING} ^q=([^&]*)&url=([^&]+)
RewriteRule ^/redirecturl$ %[b]2?[/b] [R=301,L]

And it might be advisable to do some basic checking on the passed URL as well:

RewriteCond %{QUERY_STRING} ^q=([^&]*)&url=(https?://([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+([a-z]{3,6}¦co\.[a-z]{2})[^&]+) [NC]
RewriteRule ^/redirecturl$ %[b]2?[/b] [R=301,L]

The pattern here will accept subdomains and domains starting and ending with letters or numbers with 'internal' hyphens allowed, and TLDs of the form ".com" or ".info", or ".museum", or of the ".co.uk" variety.

Replace the broken pipe "¦" character in the code above with a solid pipe character before use; Posting on this forum modifies the pipe characters.

To resolve back-references to nested parentheses, count the left parentheses.

Jim

[edit] Corrections (bolded) to remove query string from redirected URL. [/edit]

[edited by: jdMorgan at 2:36 pm (utc) on Oct. 22, 2008]