[英]Keep URL the same, load index.php
我的問題可能是愚蠢的,但我用Google搜索並沒有找到答案......
假設我想在這個給定的URL中訪問我的網站:www.mywebsite.com/something/something_else/?some_query_string = true(我把查詢字符串放在那里,因為它會在那里,我不知道它是否會使htaccess文件的任何差異)
我希望它保持URL相同,但無論什么URL(不在服務器的根目錄中)都加載索引文件。 我的服務器有一個“應用程序”文件夾,其中包含所有代碼。
我怎樣才能做到這一點?
謝謝!
使用htaccess將所有請求重寫為index.php(請求文件/目錄/鏈接且存在時除外):
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
如果要使用Rewrite將請求由DocumentRoot 外部的文件處理,則可以與Alias指令結合使用。
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* application/index.php [PT]
Alias application /path/to/application
注意RewriteRule上的[PT]
意味着“通過” - 它確保重寫的url被傳遞給其他apache模塊,這些模塊在處理它時可能會很有趣。
結果我回答了我自己的問題:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application/index.php?url=$1 [QSA,L]
如果URL不存在,它會將index.php文件加載到“application”文件夾中,並保持URL相同,這正是我需要的...
謝謝你的回答!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.