从htaccess上的url中删除/索引

时间:2017-03-11 02:16:48

标签: php .htaccess

我当前的网址看起来像[mysite].com/index

我使用以下.htaccess代码删除了.php,但我无法从网址中删除索引。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

如何从网址中删除'index'?

修改

我发现为什么它不起作用因为Windows托管不支持htaccess方法。

2 个答案:

答案 0 :(得分:2)

使用

DirectoryIndex index.php

现在apache会将index.php视为目录索引,您不必在url栏中键入index或index.php。

答案 1 :(得分:0)

实际上,删除页面名称并不是一个好习惯。

这可能会导致错误,而且对SEO也不利。

我强烈建议您使用友好的URL来删除PHP扩展(您现在正在做的方式)或者将其他名称更友好。

例:

RewriteEngine On
RewriteRule ^home/?$           /my_new_index.php             [NC,L]
RewriteRule ^new-order/?$      /new_order_from_client.php    [NC,L]

这是最好的做法!

相关问题