.htaccess to redirect a specific page to root

元气小坏坏 提交于 2019-12-11 11:10:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!