简体   繁体   English

多个页面的URL重写但查询相同

[英]URL Rewrite for multiple pages but same query

As of now I have one generic query "view" which I'll use on most pages... 截至目前,我有一个通用查询“视图”,将在大多数页面上使用...

My rewrite is: 我的重写是:

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

My url is: 我的网址是:

classroom.php?view=creation school.php?view = creation

I want it to look like: 我希望它看起来像:

classroom/creation 教室/创作

I have it working but it screwed up other urls 我有它的工作,但它搞砸了其他网址

dashboard.php was just /dashboard dashboard.php只是/ dashboard

but broke when I did the first rewrite rule... 但是当我做第一个重写规则时就坏了...

These things are a pain to understand. 这些东西很难理解。

My Question is how can i have /dashboard, /classroom, /classroom/creation work? 我的问题是,如何让/ dashboard,/ classroom,/ classroom / creation工作?

EDIT: I got it working with: 编辑:我与它一起工作:

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

The first 2 rules are for external redirect, which turns .php into a directory like format rest of the rules are for the internal redirect which keeps the pretty URL and doesn't show the redirect. 前两个规则用于外部重定向,它将.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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM