[英]override apache rewrite rules with htaccess
在承載多個域的服務器上工作。 在apache config中的某處是為所有域設置的重寫規則。
發生的情況是,如果用戶轉到example.com/foo,則應該將他們重定向到example.com/foo_bar
但是,在一個域中,我想覆蓋此行為,以便url保持在example.com/foo且不重定向。 我一直在搜索並嘗試各種規則和條件都無濟於事。 我無權訪問apache配置,但是我在此域上使用.htaccess進行一些重寫規則。
這是我在.htaccess中的重寫規則:
<IfModule mod_rewrite.c>
RewriteEngine on
# this isn't working
# RewriteRule ^(foo)($|/) - [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1
# this didn't work either
# RewriteRule ^/foo index.php?/$1 [L]
</IfModule>
嘗試將/foo_bar
重定向回/foo
。
當Apache處理重寫規則時,它會多次運行它們,您可以在打開debug時看到這些規則。 我認為您遇到的情況是您試圖在第一遍中匹配URI,但是Apache已將其修改為/foo_bar
。
另外,作為調試的問題,您應該嘗試在您控制的環境中重新創建問題。 向您的系統管理員詢問全局配置的副本,並鏡像您要約束的設置。
您可以為一個域創建例外:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(?:www\.)?domain\.com$ [NC]
RewriteRule ^foo(/.*)?$ /foo_bar$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.