Apache .htaccess虚荣/Nice URL导致出现404错误
我最近在.htaccess文件中不再使用它Apache .htaccess虚荣/Nice URL导致出现404错误,apache,.htaccess,http-status-code-404,errordocument,vanity-url,Apache,.htaccess,Http Status Code 404,Errordocument,Vanity Url,我最近在.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/ind
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错误,但保留(或保留类似的东西)我的新系统
另外:我已经重新编写了引擎,并在.htaccess中定义了404错误页。根据您显示的示例,您可以尝试以下规则吗。请确保在测试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]
对于每个不包含
/
和
且不是目录的请求,您当前的规则将重写为index.php?page=
。使用此规则无法获取常规404页面。你必须好好想想你为什么需要这个规则。让我们来看看。