【发布时间】:2021-12-17 02:01:40
【问题描述】:
我正在尝试重写规则,已经卡了这么久。
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=/$1 [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?
【问题讨论】:
-
错误日志对此有何评论?
-
您的 .htaccess 在哪里?
-
错误日志显示 [pid 4448] [client ::1:55666] AH00124:由于可能的配置错误,请求超出了 10 个内部重定向的限制。如有必要,使用“LimitInternalRecursion”增加限制。使用“LogLevel debug”获取回溯。
-
它位于 localhost/site/.htaccess
-
可能是因为只进行了内部重写,而不是外部重定向。将
R标志添加到您的规则中(为了测试,建议使用R=302,您可以稍后在一切正常时将其更改为301。)