views:

603

answers:

3

My rewriterule with a condition is working fine as below:

http://www.sitename.com/index.php?n=text redirects to http://www.sitename.com/pages/text

and the page renders properly, however, there is a problem that with the redirected URL the arguments are also added to the URL. So actually in address bar it looks like-

http://www.sitename.com/pages/text?n=text

Could anyone help me on this? The htaccess code is given below.

RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule index.php http://www.sitename.com/pages/%1 [r=301,nc]
+1  A: 

You probably want to catch "index.php.*". Otherwise mod_rewrite only replaces the "index.php" part of the URL "index.php?n=text" with the new URL.

Guss
A: 

Guss,

From what you suggested, i reconstructed it as follows:

RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule index.php.* http://www.sitename.com/pages/%1 [r=301,nc]

This doesnt seem to be working either. Can you please elaborate on what you have said?

thank you aditya

Instead of adding a new answer, please update (edit) your question indicating the update and comment on Guss's answer.
David Citron
A: 

don´t use the url in the rewrite rule, apache then sends a http 200 code and then the 301...

try sth. like this:

RewriteRule (index\.php)(?n=)(.*) /pages/$3 [r=301]
Tobiask