Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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 仅向一个目录中的文件添加html扩展名_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess 仅向一个目录中的文件添加html扩展名

.htaccess 仅向一个目录中的文件添加html扩展名,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,尝试重写如下所示的链接: /content/about-me ……为此: /content/about-me.html 这是我工作的必要条件。我使用此htaccess规则不断收到内部服务器错误: RewriteRule ^content/(.*) /content/$1.html [NC,L] 知道我做错了什么吗?网络上有大量的示例,但不能完全正确。您的重写规则(模式)太宽,将捕获已重写的URL。重写已经重写的URL将导致无限重写循环,Apache会智能地检测并中止此类请求,并产生500个

尝试重写如下所示的链接:

/content/about-me
……为此:

/content/about-me.html
这是我工作的必要条件。我使用此htaccess规则不断收到内部服务器错误:

RewriteRule ^content/(.*) /content/$1.html [NC,L]
知道我做错了什么吗?网络上有大量的示例,但不能完全正确。

您的重写规则(模式)太宽,将捕获已重写的URL。重写已经重写的URL将导致无限重写循环,Apache会智能地检测并中止此类请求,并产生500个错误

例如:

  • 原始请求:
    /hello/pink kitten
  • 第一次(初始)重写:
    /hello/pink kitten.html
  • 第二周期:重写为
    /hello/pink kitten.html.html
  • 第三个周期:重写为
    /hello/pink kitten.html.html.html
  • 。。。等等
更正确的方法(少数几种可能的方法之一)——在重写之前将检查此类html文件是否存在:

# add .html file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^content/(.+)$ /content/$1.html [L]

这是你的整个.htaccess文件吗?是否启用mod_重写?您是否已查看Apache错误日志(如果您有权访问它)以查看任何错误消息?RewriteRule ^content(/.*)上的RewriteEngine?$/content$1.html[NC,L]我以为它正在重写已重写的。非常感谢你为我指明了正确的方向。