如何使用RewriteRules从HTML文件中创建干净的URL?

时间:2012-01-27 06:50:20

标签: .htaccess mod-rewrite

我目前有这个:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /folder/

RewriteRule ^(.+) $1.html [NC]

我在folder中有html页面,我希望这些文件能够提供其他页面。例如:

/folder/about应该投放/folder/about.html

/folder/test应该投放/folder/test.html

问题是上面的重写脚本给了我500个内部错误。我如何实现我想做的事情?

编辑:

我在错误日志中看到此错误:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

1 个答案:

答案 0 :(得分:0)

也许有一个斜线问题。试试这个:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /folder/
RewriteCond $1 !\.html$
RewriteRule (.*) $1.html [QSA,NC,L]

如果不起作用,请尝试:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /folder
RewriteCond $1 !\.html$
RewriteRule (.*) $1.html [QSA,NC,L]

如果您只想更改字母和数字(例如wwW.site.com/abdd0456 www.site.com/afdf/sdqfsd),请执行以下操作:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /folder/
RewriteCond $1 !\.html$
RewriteRule ([a-zA-Z0-9]*) $1.html [QSA,NC,L]

[编辑:添加L指令]