0

I have a url:

http://domain.com/i.php?c=PT and I Rewrote it to http://domain.com/PT successfully. But When I browse http://domain.com/i.php?c=PT, it wont redirect to http://domain.com/PT. Is there anyway to both redirect and rewrite it?

My .htaccess:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^c=([a-zA-Z][a-zA-Z])$
RewriteRule ^/index.php$ /%1%2? [R=301,L]
RewriteRule ^([a-zA-Z][a-zA-Z])$  i.php?c=$1$2 [NC,L]

Thanks

Update #1: I want to redirect from domain.com/i.php?c=PT -> domain.com/PT.

I don't have index.php file.

Kevin Nguyen
  • 199
  • 1
  • 2
  • 8

1 Answers1

0

I'm not sure what behavior do you want, I see no mention of index.php in your request, but it is in your configuration. Anyway this rewrites any URL from the form hostname/XX to hostname/i.php?c=XX

RewriteEngine On
RewriteRule ^/([a-zA-Z]{2})$  /i.php?c=$1 [R=301,NC,L]

For the opposite translation:

RewriteCond %{QUERY_STRING}  ^c=([a-zA-Z]{2})$
RewriteRule ^/i.php$         /%1? [R=301,NC,L]

And you can debug your rewrite rules adding:

RewriteEngine On
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 3
ColOfAbRiX
  • 1,110