截至目前,我有一个通用查询“视图”,我将在大多数页面上使用...
我的改写是:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.php?view=$2 [L]
我的网址是:
classroom.php?视图=创建
我希望它看起来像:
教室/创建
我有它的工作,但它搞砸了其他网址
dashboard.php只是/ dashboard
但是当我完成第一次重写规则时就崩溃了......
这些事情很难理解。
我的问题是我如何进行/仪表板,/课堂,/课堂/创作?
编辑:我得到了它:RewriteRule ^([a-zA-Z0-9_-]+)$ $1.php [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.php?view=$2 [L]
答案 0 :(得分:0)
前两个规则用于外部重定向,将.php
转换为类似格式的目录。其余规则用于内部重定向,保留漂亮的URL并且不显示重定向。
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Redirect /classroom.php?view=creation to /classroom/creation
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+classroom\.php\?view=([^\s]+) [NC]
RewriteRule ^ /classroom/%1? [R=302,L]
# Redirect /classroom.php to /classroom and /dashboard.php to /dashboard
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(classroom|dashboard)\.php [NC]
RewriteRule ^ /%1 [R=302,L]
# Internally forward /classroom/creation to /classroom.php?view=creation
RewriteRule ^classroom/(.*)/?$ /classroom.php?view=$1 [L,QSA,NC]
# Internally forward /classroom to /classroom.php and /dashboard to /dashboard.php
RewriteRule ^(classroom|dashboard)/?$ /$1.php [L,QSA,NC]