问题
There are several variant questions on this on SO, but I did not find one that answers my specific problem.
I want to add a rewrite rule to my htaccess that will take all traffic going to
http://example.com/blog/its-a-sunny-day
and redirect to
http://example.com
Ideally this should be done via 302, as it will be changed later.
回答1:
Redirect /blog/its-a-sunny-day http://example.com
This seems to work.
回答2:
Enable mod_rewrite and .htaccess through httpd.conf
and then put this code in your .htaccess
under DOCUMENT_ROOT
directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^blog/its-a-sunny-day/?$ / [L,R,NC]
回答3:
Create a cgi/php file for sending a redirect header. Then write a rewrite rule to replace "blog/its-a-sunny-day" with "path/to/redirect.php". For example:
/redirect.php:
<?php header( 'Location: /' ) ; ?>
/.htaccess:
RewriteEngine on
RewriteRule ^blog/its-a-sunny-day$ /redirect.php
来源:https://stackoverflow.com/questions/11063716/htaccess-to-redirect-a-specific-page-to-root