Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 如何使用.htaccess为主页和子页执行301重定向?_Apache_.htaccess_Redirect_Http Status Code 301 - Fatal编程技术网

Apache 如何使用.htaccess为主页和子页执行301重定向?

Apache 如何使用.htaccess为主页和子页执行301重定向?,apache,.htaccess,redirect,http-status-code-301,Apache,.htaccess,Redirect,Http Status Code 301,我们有一个全球网站和一些国家的本地网站。现在我们需要将所有本地网站重定向到全球网站,这样我们就可以在全球网站上拥有每个国家的主页。我们将使用全球网站的子页面。我的.htaccess如下所示: Redirect 301 / http://newdomain.com/uk Redirect 301 /about-us/ http://newdomain.com/about-us/ Redirect 301 /contact-us/ http://newdomain.com/contact-us/

我们有一个全球网站和一些国家的本地网站。现在我们需要将所有本地网站重定向到全球网站,这样我们就可以在全球网站上拥有每个国家的主页。我们将使用全球网站的子页面。我的.htaccess如下所示:

Redirect 301 / http://newdomain.com/uk
Redirect 301 /about-us/ http://newdomain.com/about-us/
Redirect 301 /contact-us/ http://newdomain.com/contact-us/
它适用于主页,但不适用于子页面。与其将它们重定向到“”,不如继续重定向到“”

怎么办

永远不要使用301重定向 (除非1)你知道你在做什么2)你知道你在做什么的后果3)你已经使用302重定向对配置进行了广泛的测试)

我猜在你的情况下,上述三项规定都没有得到满足

在作为重定向参数提供的第一个路径上有一个。要强制文本匹配,请使用重定向匹配和锚定(例如“^/$”)。确保使用302,直到它正常工作

顺便说一句,从浏览器中获取301重定向是很困难的——仅仅清除缓存并不总是有效的