我努力做了2个小时,但最后我放弃了。
我有两个条件:
1.如果用户请求php文件重定向cms / index.php?request = $ 1
2.如果用户请求与php不同的东西(png,css,jpg)重定向cms / website / $ 1
第一条规则有效但我无法应用第二条规则。当用户请求/cms/style.css时,Apache重定向cms / website / style.css并再次重定向cms / website / website / style.css并循环。
我的htaccess文件是这样的:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*\.php) /cms/index.php?request=$1 [L]
RewriteRule (.*\.!(php)) /cms/website/$1 [R,L]
注意:我不确定最后的正则表达式是否正确。它返回500. error_log输出为
"[Tue Aug 16 16:26:11 2011] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace."
答案 0 :(得分:1)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)\.php$
RewriteRule (.*)\.(.*)$ /cms/website/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.*)\.php$
RewriteRule (.*)\.php /cms/index.php?request=$1 [L]