0

到目前为止,我有一个通用查询“视图”,我将在大多数页面上使用它......

我的重写是:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.php?view=$2 [L]

我的网址是:

课堂.php?view=创作

我希望它看起来像:

课堂/创作

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

dashboard.php 只是 /dashboard

但是当我做第一个重写规则时就坏了......

这些事情很难理解。

我的问题是我怎样才能拥有 /dashboard、/classroom、/classroom/creation 工作?

编辑:我得到它的工作:

RewriteRule ^([a-zA-Z0-9_-]+)$  $1.php [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.php?view=$2 [L]
4

1 回答 1

0

前 2 条规则用于外部重定向,它会变.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]
于 2013-07-22T16:30:54.193 回答