【问题标题】:.htaccess Vanity/Nice URLs Causing 404 Error to be Homepage.htaccess Vanity/Nice URLs 导致 404 错误成为主页
【发布时间】:2021-04-19 13:07:02
【问题描述】:

我最近不再在我的 .htaccess 文件中使用它

RewriteRule ^example index.php?page=example [L]

到这里:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^./]+)/?$ index.php?page=$1 [L,QSA]

问题是,如果我访问 example.com/euffhfrfreif 之类的内容 - 它只会显示我的主页。

我正在尝试配置虚 URL,以便访问者不会使用 example.com/index.php?page=contact,而只会访问 example.com/contact - 我在网上看到过很多这样的内容,并且它应该对谷歌等更好。

此错误不适用于任何文件夹,因此访问 example.com/djfhds/fdjdnf 将显示 404 错误。

我怎样才能恢复我的 404 错误但保留(或保留类似的东西)我的新系统?

另外:我打开了 rewriteengine 并在 .htaccess 中定义了一个 404 错误页面。

【问题讨论】:

  • 您当前的规则是为每个不包含/ 和. 且不是目录的请求重写到index.php?page=。使用此规则,您无法获得常规的 404 页面。您必须正确思考为什么需要此规则。

标签: apache .htaccess http-status-code-404 errordocument vanity-url


【解决方案1】:

根据您显示的示例,您能否尝试以下规则。请确保在测试 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteRule ^([^./]+)/?$ index.php?page=$1 [L]

问题是您在 index.php 中使用 else 语句来显示您的主页。

将你的 else 语句更改为 404 错误页面并将你的主页设为index.php?page=home,然后将其添加到 htaccess:

RewriteRule ^([^./]+)/?$ index.php?page=$1 [L]

【讨论】:

猜你喜欢
  • 2011-10-08
  • 1970-01-01
  • 2022-12-10
  • 2015-05-24
  • 2021-10-04
  • 1970-01-01
  • 2019-12-10
  • 2012-10-16
  • 1970-01-01
相关资源
最近更新 更多