Search code examples
php.htaccessdynamichttp-redirecthttp-status-code-301

htaccess 301 redirect with a dynamic page?


In htaccess, how do you 301 redirect dynamic pages?

For example, what if I wanted a rule that made /get.php?i=1234 to redirect to /i/1234, etcetera?


Solution

  • You can use mod_rewrite like redirection as in this code:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{QUERY_STRING} ^(i)=([^&]+)(&|$) [NC]
    RewriteRule ^get\.php$ %1/%2? [L,R=301,NC]