2012-03-22 94 views
1

编辑#2:我停用了404页,并没有发现默认页说,这是寻找后,名为.php的一个网址:mod_rewrite的和干净的URL部分工作

“的请求的URL /事件/ 2012。在这台服务器上找不到php“

所以现在我相信它正在寻找一个实际的文件,当它不存在。任何人??

编辑#1:看起来像循环重定向是固定的,但我仍然不知道为什么重写不起作用的事件页面。/events/works蛮好的,但是/ events/2012/title-id /去了404./breweries /和arizona-breweries/brewery-name/works也是如此,我不确定我错过了什么。

我想添加一个新的目录结构与我的events.php页面。 events/2012/... 我在Breweries.php下有另一个目录结构,工作得很好。

当我尝试sitename.com/events/2012/title-of-event-3/重定向循环加载一个事件,并说:“过多的重定向”和URL看起来像这样:

站点名。 com/events/2012/title-of-event-3.php.php.php.php.php.php.php.php.php.php.php.php.php/

我找了6个小时寻找答案足够。任何和所有帮助表示赞赏!

(没有我没有sitename.com在我真正的htaccess文件)

我htaccess文件:

Options +FollowSymLinks -Multiviews 
RewriteEngine on 

RewriteBase/

#remove php file extension 
#RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteCond %{REQUEST_URI} !^/blog/ 
RewriteRule ^(.*)/$ $1.php [QSA,L] 

#clean urls 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^events/([0-9]+)/(.*)-([0-9]+)/$ events.php?year=$1&title=$2&id=$3 [R,NC,QSA] 
RewriteRule ^(.*)-breweries/$ breweries.php?loc=$1 [NC,QSA] 
RewriteRule ^(.*)-breweries/(.*)/$ breweries.php?loc=$1&brewery=$2 [NC,QSA,L] 

#Force trailing slash after url 
RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteCond %{REQUEST_URI} !example.php 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ^(.*)$ http://www.sitename.com/$1/ [L,R=301] 

#force www 
RewriteCond %{HTTP_HOST} !^www.sitename.com$ 
RewriteRule ^(.*)$ http://www.sitename.com/$1 [R=301,L] 

回答

0

我解决了它。我不得不移动URL部分下面的.php扩展部分(就在force www部分之上),它就起作用了。显然啤酒厂部分曾经在一个正确的地方,所以它继续工作,但当我试图增加一个新的重写它不能正常工作。

1

的问题是规则1和互动5.

规则5在没有映射到文件名的任何URI之后强制/因此

http://sitename.com/events/2012/title-of-event-3.php.php -> 
    http://sitename.com/events/2012/title-of-event-3.php.php/ 

然后排除1映射

http://sitename.com/events/2012/title-of-event-3.php.php/ -> 
    http://sitename.com/events/2012/title-of-event-3.php.php.php 

问题是你如何陷入这种循环摆在首位?我不知道为什么,因为events/2012/title-of-event-3/会匹配^events/([0-9]+)/(.*)-([0-9]+)/,但我已经看到这与意想不到的子查询befire,所以我建议你消除一个射击子查询的可能性,通过添加第一条规则搞砸你的逻辑:

RewriteCond %(IS_SUBREQ}%{ENV:REDIRECT_END} y|1 
RewiteRule^       - [L] 

并将E=END:1添加到您想要终止重写周期的规则标志。

+0

好了,现在我们取得了一些进展,我只好用修改后的版本工作的代码,因为它一直给我一个500错误: 'RewriteCond%{ENV:REDIRECT_STATUS}!^ $ [OR]' 'RewriteCond%{IS_SUBREQ} = true' 'RewriteRule。* - [L]' This停止循环重定向,但我仍然无法访问/ events/2010/title-3 /。但是现在,它只显示了一个正常的404 Not Found而不是.php.php.php等。 – n1ch0la5 2012-03-23 13:33:53

+0

您的docroot中有events.php文件吗? – TerryE 2012-03-25 14:44:50

+0

是的,events.php位于根文件夹中。我完全被难住了。 – n1ch0la5 2012-03-26 16:07:07

0

大家好,我认为这会有很大的帮助 你需要做的是允许某种排序映射,比如/ someurl/somescript“映射到/ someurl/somescript。但是当你使用这种映射时,记得要排除一些可能属于目录的重要部分,例如/ someurl/css肯定会指向你的样式表文件夹,而你不希望它被追加或映射到例如/someurl/css.php <一旦执行重写规则。 利用这一点,它会为/ someurl/somescript或/ someurl/DIR/somescript或/ someurl/dir11/DIR2/somescript

#prevents loops 
Options +FollowSymlinks -MultiViews 
RewriteEngine On 
RewriteBase/
#conditions below prevents directory 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !css$ [NC] 
RewriteCond %{REQUEST_FILENAME} !js$ [NC] 
#conditions below exclude some of the file extension that you might be using on your system 
RewriteCond %{REQUEST_URI} !\.ico$ [NC] 
RewriteCond %{REQUEST_URI} !\.css$ [NC] 
RewriteCond %{REQUEST_URI} !\.js$ [NC] 
RewriteCond %{REQUEST_URI} !\.svg$ [NC] 
RewriteCond %{REQUEST_URI} !\.png$ [NC] 
RewriteCond %{REQUEST_URI} !\.jpeg$ [NC] 
RewriteCond %{REQUEST_URI} !\.jpg$ [NC] 
#condition checks for any file that dont ends with .php which would have selected all the file that forced to exclude all the file not ending with .php thus including even dir that why to exclude them above 
RewriteCond %{REQUEST_URI} !\.php [NC] 
# Map internally to the resource, showing the "pretty" URL in the address bar 
#note that /? indicate zero or more of/and [^/] states do nt include/on the begining, the + indicates that one or more with fullstop preceding it means one or more of any character 
#RewriteRule ^([^/]+)/? /$1.php [NC] 
#note that the rule below is different from above because it allows one or more ^([^/]+)/? which is achieved by having it grouped by() and appending a plus 
RewriteRule (^([^/]+)/?)+ %{REQUEST_URI}.php [NC]