如何从我的网站的主页 URL 扩展名中删除 /index



您将如何从网站的主页URL中删除索引扩展?当我访问我的网站时,URL 显示为 www.example.com/然后稍后,如果我单击关于页面并单击我上面有一个 href 的徽标,然后重定向回主页,然后显示 www.example.com/index - 有没有办法简单地从索引页面中删除它只是因为它看起来不是那么好。

我正在使用 Perch 提供的 .htaccess 文件 ifModule 删除.php文件扩展名,如果这有助于:

<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect to PHP if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)$ $1.php [L,QSA]
</IfModule>

任何帮助都会很棒!谢谢

最简单的方法是将徽标上的链接从index.php更改为/,这是您网站的根...

<a href="/index">...</a> 
... becomes ...
<a href="/">...</a> 

否则,您可以添加与/index匹配的 Apache RewriteRule 并使用301 HTTP 代码重定向到 /

RewriteRule ^(.*)index$ / [R=301,L] 
这是

您可以放置的第一个规则,以隐藏/删除索引.php从任何地方:

RewriteCond %{THE_REQUEST} /index.php [NC]
RewriteRule ^(.*?)index.php$ /$1 [L,R=301,NC,NE]

此规则:

RewriteRule ^(.+)$ $1.php [L,QSA]

仅对请求的 URL 执行内部重写。这意味着重写导致的任何 URL 更改对客户端都不可见。

这意味着如果你的HTML包含正常的"php是可见的"链接,那就是用户在他们的地址中看到的坏。因此,您的所有客户端链接都必须是重写的no-php版本。

<a href="/">..</a> This is ok - no php visible, user see http://example.com/
<a href="/index">..</a> Also ok: http://example.com/index
<a href="/index.php">..</a> Nope: user sees http://example.com/index.php

最新更新