Etienne Dupuis Etienne Dupuis - 3 months ago 9
PHP Question

my .htaccess redirection fails

htaccess is enabled, i have the canonicalization running (no-www to www.)

I'm trying to use htaccess to do the following

www.domain.com/page.php?i=Page1
www.domain.com/page.php?i=Page2


To

www.domain.com/Page1
www.domain.com/Page2


I tried using this code snippet, with no luck so far:

rewriterule ^([a-zA-Z0-9_-]+)/$ page.php?i=$1


However I think I'm going the reverse way. I can't find example for this.
I have this but I can't make it work.

Answer

Try this:

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/page\.php$
RewriteCond %{QUERY_STRING} ^i=([a-zA-Z0-9_-]+)$
RewriteRule ^(.*)$ http://www.domain.com/%1? [R=302,L]

taken from: http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/