[英].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.