我有一个简单的。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
,如果添加了更多斜杠则不适用。
谢谢!
不要在target中使用绝对路径/
。这是你可以保存在根目录和子目录中的。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文件工作在
是否也有相同的 ?Htaccess 文件在"may9-new"子文件夹?
如果您也有我在may9-new子文件夹中保留了网站的另一个副本(与相同的。htaccess文件复制到该目录)。
,那么可能存在冲突,请尝试修改。Htaccess 子文件夹的文件:
RewriteRule ^(.+)$ /may9-new/index.php?path=$1 [NC,QSA]