Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
.htaccess URL写入问题_.htaccess_Url_Mod Rewrite_Rewrite - Fatal编程技术网

.htaccess URL写入问题

.htaccess URL写入问题,.htaccess,url,mod-rewrite,rewrite,.htaccess,Url,Mod Rewrite,Rewrite,我目前在一个默认启用mod_rewrite的服务上托管一个站点。我用编辑了.htaccess RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html 但它只允许使用“site.com/pagename”访问站点。我希望它将url改写为“site.com/pagename”,而不

我目前在一个默认启用mod_rewrite的服务上托管一个站点。我用编辑了.htaccess

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html
但它只允许使用“site.com/pagename”访问站点。我希望它将url改写为“site.com/pagename”,而不是“site.com/pagename.html”

我已经尝试了一百万种不同风格的代码,它不会重写url以排除.html。HTML代码将页面链接为

<a href="index.html">Text</a>

如果这有区别的话


提前感谢您的帮助。

非常感谢。工作完美。但是,有没有办法将“site.com/index”简化为“site.com”?未经测试,但应在上述操作之前插入:
RewriteRule^index\.html$/[R=301,L]
然后
RewriteRule^(.*)/index\.html$/$1/[R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html?\ HTTP
RewriteRule (.+)\.html?$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html