【发布时间】:2019-04-11 15:09:14
【问题描述】:
我有一个网址说https://example.com/index.php/foo/bar
我希望 example.com 中的任何页面转到 https://example.com
我希望浏览器使用主页 url 进行更新。这是任何网址都可以访问该网站。这可能包括带有查询的网址,即https://example.com/?foo=bar。从字面上看,所有/任何页面都可以转到主页
我已经尝试了许多 RewriteRules 重定向,但没有一个做我想要的(最近的是加载 index.php,但 url 仍然是错误的)
我想使用 .htaccess 但如果在 .conf 文件中更容易,我会这样做
只是想我可以在 index.php 文件中执行此操作,方法是检查是否重新加载带有标题的页面是否有查询。会推荐这个吗?
我使用的是 ubuntu 16.04 apache 2.4,我有 php 7.1,所有模块都启用以处理重定向和重写(网站上有 wordpress,但现在包含即将推出的页面,没有其他内容)
htaccess 中当前但不工作的版本是
RewriteEngine On
RewriteBase /
# Make sure there is a query string
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /? [R=301,L]
这将正确加载带有查询字符串 (https://example.com?foo=bar) 的 url,但如果我使用 https://example.com/index.php/foo/bar,浏览器不会更新重定向的 url/ index.php 中的脚本和图像未加载,并且与查询一样字符串的 url 在浏览器中保持不变。
【问题讨论】:
标签: .htaccess