我为我的学校建立了一个小型家长/教师社交网络。我使用我的.htaccess
文件使指向教师资料的链接更清晰,并在所有 url 中添加尾部斜杠。转到/teachers/teacher-name/
链接(有时)重定向到/teachers/teacher-name.php.php.php.php.php.php.php.php...
以下是我的.htaccess
文件时,我遇到了这个问题。有时,如果我在 Chrome 中清除浏览器缓存,它会暂时修复它。我不能完全正确的.htaccess
语法,但我很熟悉它。任何建议表示赞赏!
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
编辑:我附上了我在说什么的截图。