Reputation: 89
Edit #2: i disabled my 404 page and the default not found page says that it's looking for a url with .php after it:
"The requested URL /events/2012.php was not found on this server"
So now i believe it's looking for an actual file, when it doesn't exist. anyone??
Edit #1: looks like the looping redirect is fixed, but I still can't figure out why the rewrites aren't working for the events page. /events/ works just fine, but /events/2012/title-id/ goes to a 404. /breweries/ and arizona-breweries/brewery-name/ works also so i'm not sure what i'm missing.
I'm trying to add a new directory structure with my events.php page. events/2012/... I have another directory structure under breweries.php that works just fine.
When i try to load an event sitename.com/events/2012/title-of-event-3/ it redirect loops and says "too many redirects" and the url looks like this:
sitename.com/events/2012/title-of-event-3.php.php.php.php.php.php.php.php.php.php.php/
I figure 6 hours of searching for an answer were enough. Any and all help appreciated!
(and no i don't have sitename.com in my real htaccess file)
My htaccess file:
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]
Upvotes: 1
Views: 432
Reputation: 1
hello everyone i think this will help much what you need to do is to allow some sort mapping that is a request such as /someurl/somescript" be mapped to /someurl/somescript.php but as you use this sort of mapping remember to exclude some of the important parts that might fall to directory such as /someurl/css will definitely be pointing to your style sheet folder and you would not want it to be appended or mapped to something such as /someurl/css.php< once a rewrite rule is executed. use this, it will work for /someurl/somescript or /someurl/dir/somescript or /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]
Upvotes: 0
Reputation: 89
I solved it. I had to move the section that removed the .php extension below the url rewrite section (just above the force www part) and it worked. apparently the breweries section had been in the right place at one time so it continued to work, but when I tried to add a new rewrite it wouldn't work properly.
Upvotes: 0
Reputation: 10878
The problem is an interaction of rules 1 and 5.
Rule 5 forces a /
after any URI that doesn't map to a filename hence
http://sitename.com/events/2012/title-of-event-3.php.php ->
http://sitename.com/events/2012/title-of-event-3.php.php/
And then rule 1 maps
http://sitename.com/events/2012/title-of-event-3.php.php/ ->
http://sitename.com/events/2012/title-of-event-3.php.php.php
The issue is how do you get stuck in this loop in the first place? I am not sure why because events/2012/title-of-event-3/
will match against ^events/([0-9]+)/(.*)-([0-9]+)/
, but I've seen this with unintended sub-queries befire, so I would suggest that you eliminate the possibility of a firing subquery screwing up your logic by adding a first rule:
RewriteCond %(IS_SUBREQ}%{ENV:REDIRECT_END} y|1
RewiteRule ^ - [L]
and adding E=END:1
to your rule flags that you want to terminate the rewrite cycle on.
Upvotes: 1