0
這裏是我的所有規則避免衝突,爲了清楚重定向根與htaccess的子文件夾,但動態網址
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
# RewriteBase/
# Adaptive-Images -----------------------------------------------------------------------------------
# Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
# RewriteCond %{REQUEST_URI} !ignore-this-directory
# RewriteCond %{REQUEST_URI} !and-ignore-this-directory-too
RewriteCond %{REQUEST_URI} !cache
RewriteCond %{REQUEST_URI} !img
RewriteCond %{REQUEST_URI} !ui
# don't apply the AI behaviour to images inside AI's cache folder:
RewriteCond %{REQUEST_URI} !ai-cache
# Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
# to adaptive-images.php so we can select appropriately sized versions
RewriteRule \.(?:jpe?g|gif|png)$ /adaptive-images.php
# END Adaptive-Images -------------------------------------------------------------------------------
# Add a trailing slash to folders that don't have one
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
# Exclude these folders from rewrite process
RewriteRule ^(admin|ajax|img|inc|js|lang|lib|pub|tpl|ui)($|/) - [L]
# Redirect root requests to /home/ folder
RewriteRule ^(/home/)?$ /home/ [NC,L]
# Start rewriting rules
RewriteRule ^(.*)/(.*)/(.*).htm$ /home/details.php?rCat=$1&kParam=$3 [NC,L]
RewriteRule ^(.*)/(.*)/$ /home/master.php?rCat=$1&rCity=$2 [NC,L,QSA]
RewriteRule ^(.*)/$ /home/master.php?rCat=$1 [NC,L,QSA]
RewriteRule ^(.*).htm$ /home/page.php?rPage=$1 [NC,L]
</IfModule>
我想的是:
- 打字
www.mysite.com
重定向到www.mysite.com/home/
目錄(無需要顯示的地址欄上的/home/
部分) - 打字
www.mysite.com/home
(帶或不帶斜線)停留在www.mysite.com/home/
目錄;有在加時的目錄沒有一個 - 打字尾隨斜線上面列表中的規則(或點擊類似鏈接)
www.mysite.com/my-category
重定向到一個動態的URL像/home/master.php?rCat=my-category
正如你所看到的, /home/
是唯一的「真實」目錄。目前,我懷疑RewriteRule ^(.*)/$
儘管[L]
覆蓋RewriteRule ^(/home/)?$
:當我輸入www.mysite.com
似乎我被重定向到www.mysite.com/home
(這很好),但是這個URL被「翻譯」爲/home/master.php?rCat=home
:因爲「家」類別不存在,我得到一個空的類別頁面模板。
那麼,我該如何告訴.htaccess「不適用於/ home/path規則RewriteRule ^(.*)/$
,請停止到RewriteRule ^(/home/)?$
」?
有'-f'和'-d'爲的RewriteRules - 「這是一個文件」, 「是這樣的目錄」。例如如果URL請求的文件系統中確實存在的東西,那麼做一些事情(或不)。 –
是的,我也嘗試過'RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d'但是沒有運氣:我應該把它放在哪裏? – Ivan
在規則頂部附近的某個地方,最有可能的是,所以你不會浪費很多cpu循環測試/改寫應該完全豁免的URL。 –