重写规则一直显示内部服务器错误

Rewrite Rule keep showing Internal Server Error

我正在尝试重写规则,但一直卡住了。

RewriteEngine on
RewriteCond %{QUERY_STRING} ^page\=about$
RewriteRule ^$ /about? [L]

我想要实现的是:

来自

https://localhost/site/
https://localhost/site/?page=about
https://localhost/site/?page=food
https://localhost/site/?page=place
https://localhost/site/?page=shop
https://localhost/site/?page=place&area=west

https://localhost/site/
https://localhost/site/about
https://localhost/site/food
https://localhost/site/place
https://localhost/site/shop
https://localhost/site/place/west

每当我在我的本地主机或我的域(顶级域:www.mydomain.com)上尝试时,我总是得到: Internal Server Error


编辑: 现在我有以下代码。没有错误。

RewriteEngine on
#1) redirect the client from "/index.php/foo/bar" to "/foo/bar"
RewriteCond %{THE_REQUEST} /index\.php/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [NE,L,R]
#2)internally map "/foo/bar" to "/index.php/foo/bar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?page=/ [L]

没有错误,但如果我要去 https:///localhost/site/about 它会将我重定向到主页内容,即使 URL 是 https:///localhost/site/about

但在实时站点上,www.mysite.com,它几乎完美运行。

www.mysite.com/about √ works
www.mysite.com/shop √ works
www.mysite.com/place/west x not working

由于我是从其他来源复制的,评论说#2)内部映射“/foo/bar”到“/index.php/foo/bar”。

-如何将此地图制作到 index.php?page=about?

-如何让它适用于 www.mysite.com/place/west

您可以使用以下规则:

 RewriteEngine On
 #Redirect /site/?page=foobar to /site/foobar
RewriteCond %{THE_REQUEST} /site/(?:index\.php)?\?page=(.+)\sHTTP [NC]
RewriteRule ^ /site/%1? [L,R]
# Internally rewrite new path to the original one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:site/)?(.+)/?$ /site/?page= [L,QSA]

我还没有测试过它,但我相信它应该适用于您的网址。