2012-05-15 59 views
2

试图重写看起来像这样的链接:HTML扩展添加到文件中仅选择一个目录

/content/about-me 

...这样的:

/content/about-me.html 

这是必要的什么我的工作。我用这个htaccess规则不断收到内部服务器错误:

RewriteRule ^content/(.*) /content/$1.html [NC,L] 

任何想法我做错了什么?网上有大量的例子,但不能完全正确。

+0

那是你的全部。 htaccess的 - 文件? mod_rewrite是否启用?你有没有检查出Apache的error_log(如果你有权访问它)的任何错误消息? – vstm

+0

RewriteEngine On RewriteRule^content(/.*)?$ /content$1.html [NC,L] – cimeran

回答

1

您的重写规则(模式)过于宽泛,会捕获已重写的URL。覆盖已经重写的URL将导致无限的重写循环,Apache会以500错误智能检测并中止这样的请求。

RewriteRule Last [L] flag not working?

例如:

  • 原始请求:/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] 
+0

我以为这是重写已经重写的内容。非常感谢您指引我朝着正确的方向发展。 – cimeran