Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从我的网站的主页URL扩展中删除/索引?_Php_.htaccess_Url - Fatal编程技术网

Php 如何从我的网站的主页URL扩展中删除/索引?

Php 如何从我的网站的主页URL扩展中删除/索引?,php,.htaccess,url,Php,.htaccess,Url,如何从站点的主页URL中删除索引扩展名?当我访问我的网站时,URL显示为www.example.com/然后稍后,如果我单击about页面,然后单击带有href的徽标,然后指向主页,然后显示www.example.com/index-是否有一种方法可以简单地将其从索引页面中删除,因为它看起来不太好 如果有帮助,我将使用Perch提供的.htaccess文件ifModule删除.php文件扩展名: <IfModule mod_rewrite.c> RewriteEngine on #

如何从站点的主页URL中删除索引扩展名?当我访问我的网站时,URL显示为www.example.com/然后稍后,如果我单击about页面,然后单击带有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>

重新启动发动机
#重定向到PHP(如果存在)。
#例如,example.com/foo将显示example.com/foo.php的内容
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
RewriteCond%{REQUEST_FILENAME}.php-f
重写规则^(+)$$1.php[L,QSA]

任何帮助都会很好!谢谢

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

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

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

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

这是您可以将其作为第一条规则放置在任何位置隐藏/删除index.php的位置:

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

这是您可以将其作为第一条规则放置在任何位置隐藏/删除index.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是可见的”链接,用户将在其地址中看到这些链接。因此,所有客户端链接都必须是重新编写的非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
这没问题-没有可见的php,用户请参见http://example.com/
也可以:http://example.com/index
否:用户看到http://example.com/index.php
此规则:

RewriteRule ^(.+)$ $1.php [L,QSA]
仅对请求的URL执行内部重写。这意味着重写对URL的任何更改对客户端都不可见

这意味着如果您的HTML包含正常的“php是可见的”链接,用户将在其地址中看到这些链接。因此,所有客户端链接都必须是重新编写的非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
这没问题-没有可见的php,用户请参见http://example.com/
也可以:http://example.com/index
否:用户看到http://example.com/index.php

为什么需要301?你不能重写一下吗?你为什么需要301?你不能重写一下吗?