已經通過其他建議的問題,但沒有運氣。這些是我的 .htaccess 重寫規則,主要是為了 SEO 和用戶友好的目的:
Options SymLinksIfOwnerMatch
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(images|css|js|scripts/.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^dictionary/(.*) dictionary.php [NC,L]
RewriteRule . /index.php [L]
RewriteRule ^dict/[^/] /[^/] /(. )$ $1 [L]
</IfModule>
如果我取消對重寫規則的注釋,以便對www.xyz.com/dictionary 的任何請求并在內部重寫為www.xyz.com/dictionary.php,并添加任何查詢字串,則整個站點將停止作業。
我想要的是,對檔案夾 JS、CSS、影像和腳本的任何請求都不會被重寫(所以我沒有得到 /dictionary.images/xyz.jpg)并且不會重寫包含在 dictionary.php 中的 php 檔案。
任何對現有目錄的請求都不會被觸及,但如果一個不存在的目錄被重寫到 /index.php
我怎樣才能讓重寫的“假”目錄被重寫?我還有大約 5 個假目錄要重寫,并且 CSS、JavaScript 和影像是從正確的路徑加載的?
uj5u.com熱心網友回復:
重寫條件僅適用于下一個規則。當您在規則之間插入“字典”規則index.php及其上方的重寫條件時,它們將停止應用該規則并破壞您的站點。您需要在其他地方添加新規則。
我建議添加新行來強調哪些條件符合哪些規則。
您的dict和dictionary規則需要靠近頂部,以便您的前端控制器不會處理這些路徑( index.php)
嘗試:
Options SymLinksIfOwnerMatch
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^dict/[^/] /[^/] /(. )$ $1 [L]
RewriteRule ^dictionary/(.*) dictionary.php [NC,L]
RewriteCond %{REQUEST_URI} !^/(images|css|js|scripts/.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/317881.html
標籤:php 阿帕奇 .htaccess url重写 搜索引擎优化
