.htaccess Redirect Loop, adding multiple .php extensions
Posted
by
Ryan Smith
on Stack Overflow
See other posts from Stack Overflow
or by Ryan Smith
Published on 2012-06-27T02:22:53Z
Indexed on
2012/06/27
3:16 UTC
Read the original article
Hit count: 274
I have sort of a small parent/teacher social network set up for my school. I use my .htaccess
file to make the links to teacher profiles cleaner and to add a trailing slash to all urls. I get this problem when going to /teachers/teacher-name/
the link (sometimes) redirects to /teachers/teacher-name.php.php.php.php.php.php.php.php...
Below is my .htaccess
file. Sometimes if I clear my browser cache in Chrome it temporarily fixes it. I can't exactly wright .htaccess
syntax, but I'm pretty familiar with it. Any suggestions are appreciated!
RewriteEngine on
RewriteBase /
#remove php ext
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.php
#force trailing slash/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301]
#other rewrites
RewriteRule ^teachers/([^/\.]+)/$ /teachers/profile.php?u=$1
RewriteRule ^teachers/([^/\.]+)/posts/$ /teachers/posts.php?u=$1
RewriteRule ^teachers/([^/\.]+)/posts/([^/\.]+)/$ /teachers/post.php?u=$1&p=$2
RewriteRule ^gallery/([^/\.]+)/$ /gallery/album.php?n=$1
RewriteRule ^gallery/([^/\.]+)/slideshow/$ /gallery/slideshow.php?n=$1
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)/([^/\.]+)/$ /gallery/photo.php?a=$1&p=$2&e=$3
EDIT:I have attached a screenshot of exactly what I'm talking about.
© Stack Overflow or respective owner