繁体   English   中英

.htaccess将所有内容重定向到index.php,但将网站的副本保留在子目录中

[英].htaccess to redirect everything to index.php, but keep a copy of the website in a subdirectory

我有一个简单的.htaccess文件。 我希望它将不是文件或目录的所有内容重定向到index.php。 我将网站的另一个副本保留在may9-new子文件夹中(将相同的.htaccess文件复制到该目录中)。 但是问题是,我可以成功访问www.example.com/may9-new ,但是如果我访问www.example.com/may9-new/anything ,似乎我在根文件夹中看到该网站的版本。 。 这是.htaccess文件:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/may9-new
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA] 
</IfModule>

当涉及到.htaccess时,我几乎一无所知,所以请多多包涵。 我了解到RewriteCond是应该发生RewriteRule的条件。 所以我试图写一个条件,指出该路径不能以/may9-new开头。 RewriteCond仅适用于www.example.com/may9-new ,如果添加了更多的斜杠,则无效。

有人可以帮我找出正确的规则吗?

谢谢!

不要在目标中使用绝对路径/ 这是您可以在根目录以及子目录中保留的.htaccess:

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^index\.php$ - [L,NC]

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# route to index.php in current directory
RewriteRule ^(.+)$ index.php?path=$1 [L,QSA] 
</IfModule>

也许您需要基于主机系统进行配置。 尝试检查以下内容:

RewriteCond %{REQUEST_URI} !^/may9-new(.*)
RewriteRule ^(.+)$ /index.php?path=$1 [NC,QSA]

您还可以按照以下说明就此问题与托管服务提供商联系:

奇怪的是,此站点及其.htaccess文件在由...托管的其他域上工作。

您的“ may9-new”子文件夹中是否还具有相同的.htaccess文件?

我将网站的另一个副本保留在may9-new子文件夹中( 将相同的.htaccess文件复制到该目录中 )。

如果您也有,则可能有冲突,请尝试修改子文件夹的.htaccess文件:

RewriteRule ^(.+)$ /may9-new/index.php?path=$1 [NC,QSA]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM