对多个页面但同一查询进行URL重写


URL Rewrite for multiple pages but same query

到目前为止,我有一个通用查询"view",我将在大多数页面上使用它。。。

我的重写是:

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?view=创建

我希望它看起来像:

课堂/创作

我有它的工作,但它搞砸了其他网址

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]

前两条规则用于外部重定向,将.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]