Search code examples
.htaccesshttp-redirecthttp-status-code-301

Redirect 301 specific page alongside all pages


I'm currently using this code to redirect all request to index.php

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^([^.]+)/?$ index.php?get=$1 [L]

While having this universal code, how can I specify an individual redirect?

E.g., Redirect 301 /foo http://example.com/foo-bar


Solution

  • Place this above your current set of rules. The L flag will cause Apache to stop processing the rest of the .htaccess file. Also be sure to clear your browser cache.

    RewriteRule ^foo$ /foo-bar [R=301,L]
    

    A nice tool for testing .htaccess files can be found here http://htaccess.mwl.be/