![](/img/trans.png)
[英]How to prevent apache from forcing HTTPS in mod_rewrite redirects?
[英]mod_rewrite - Prevent multiple redirects
我的文件夾結構:
- nameoftherootfolder
-- app
-- public
--- .htaccess
--- index.php
現在我遇到的問題是,在某些情況下,我的apache經常在內部進行重寫,以至於出現500服務器錯誤,這里是日志:
[Wed Jan 05 17:51:54 2011] [error] [client 127.0.0.1] Request exceeded the limit of 3 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Jan 05 17:51:54 2011] [debug] core.c(3046): [client 127.0.0.1] r->uri = /nameoftherootfolder/public/index.php
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/public/index.php
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/public/index.php
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/nothere/
我的.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
index.php處理所有請求,如果訪問的URL錯誤(例如不存在),則也進行處理。
如果訪問的URL存在,它可以工作,但是URL是“錯誤的”,我得到那個錯誤。 我得到這個只是因為我設置了Apache別名:
Alias /nameoftherootfolder/ "C:/somepathshere/WAMP/www/nameoftherootfolder/public/"
<Directory "C:/somepathshere/WAMP/www/nameoftherootfolder/public/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
現在如何使用Apache防止過多的內部重定向? 可能有一個RewriteCond嗎? 我正在使用Apache 2.2.11。
編輯:
如果我在uri內放一個index.php/
,它可以工作,但這對SEO不友好,用戶不友好,看起來很恐怖,例如請求。 http://localhost/nameoftherootfolder/index.php/nothere/
/ http://localhost/nameoftherootfolder/index.php/index/
http://localhost/nameoftherootfolder/index.php/nothere/
或http://localhost/nameoftherootfolder/index.php/index/
http://localhost/nameoftherootfolder/index.php/nothere/
/ http://localhost/nameoftherootfolder/index.php/index/
編輯#2:
我加了之后
RewriteBase /nameoftherootfolder/
它的工作原理知道。
我加了之后
RewriteBase /nameoftherootfolder/
它現在有效。
您需要排除對index.php
本身的調用,以防止無限循環。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^.*$ index.php [NC,L]
就我而言,我在一個子域中有一個站點,該站點在Apache中配置的另一個站點的文件夾下。 這修復了我的重寫錯誤:
RewriteBase /
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.