Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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 301重定向更改URL的错误部分_Apache_.htaccess_Redirect_Mod Rewrite_Http Status Code 301 - Fatal编程技术网

Apache 301重定向更改URL的错误部分

Apache 301重定向更改URL的错误部分,apache,.htaccess,redirect,mod-rewrite,http-status-code-301,Apache,.htaccess,Redirect,Mod Rewrite,Http Status Code 301,在.htaccess文件中,我有以下重定向: Redirect 301 /About-Us http://www.example.com/about-us Redirect 301 /About-Us/Profile http://www.example.com/about-us/profile 问题在于,如果键入以下地址: www.example.com/About-Us/Profile 上面的代码将其更改为以下内容: www.example.com/about-us/Profile 简

在.htaccess文件中,我有以下重定向:

Redirect 301 /About-Us http://www.example.com/about-us
Redirect 301 /About-Us/Profile http://www.example.com/about-us/profile
问题在于,如果键入以下地址:

www.example.com/About-Us/Profile
上面的代码将其更改为以下内容:

www.example.com/about-us/Profile

简言之;它会更改URL的第一位,但不会更改第二位。我怎样才能避免这种情况?我知道重定向整个文件夹的
RedirectMatch 301^/folder//new folder
规则,但这不能满足我们的需要。此外,我也知道,将文件夹大写并不是一种好的做法。我没有建立这个网站。

找到了答案。您需要将
$
表达式添加到父文件夹的末尾,如下所示:

Redirect 301 /About-Us$ http://www.example.com/about-us  

然后,所有子文件夹和文件都将适当重定向

如果您的所有URL,或者可能至少不是文件的URL都应该是小写的,您最好只进行一次重写:

.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [A-Z] LC.php [NS,L]
LC.php
中(大写文件名是经过深思熟虑的)


你怎么样了?
<?php
$u = explode('?', $_SERVER['REQUEST_URI']);
$u[0] = strtolower($_SERVER['HTTP_HOST'] . $u[0]);
header('Location: http://' . implode('?', $u), true, 301);