块.PHP .html扩展
我使用的是Godaddy的域名,我想阻止/摆脱我的文件扩展名,例如:www.example.com/index.php
到www.example.com/index
块.PHP .html扩展
我知道的.htaccess的所以这里是我的代码重写规则
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase/
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.html
</IfModule>
有人帮我请。
在Apache上
因为你在GoDaddy的,您需要启用多视图中的.htaccess文件。
添加以下代码:
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
应该工作。参考:https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
在IIS/Windows的
IIS使用web.config文件而不是.htaccess文件。创建在根目录下的文件web.config中(或你想要的规则适用每个目录),并把下面的代码在它
<rewrite>
<rule name="hide .php extension" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rewrite>
参考:https://www.saotn.org/iis-url-rewrite-hide-php-extension/
这不工作也先生:(。我需要重新配置所有的HREF链接? –
你在@PaulKevin上托管?Apache ,IIS或其他什么东西? –
Plesk ??即时通讯不是很确定。哈哈哈,但即时通讯使用godaddy –
你面对的是什么问题? –
我想你使用的是godaddy windows hosting吗? – phpdroid
@AyushGupta有没有问题,但它不工作没有错误 –