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

发布于 2024-12-29 10:00:56 字数 628 浏览 1 评论 0原文

我目前有这个:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /folder/

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

我在该文件夹中有 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.

I currently have this:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /folder/

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

I have html pages in that folder and I want the files to serve other pages. eg:

/folder/about should serve /folder/about.html

/folder/test should serve /folder/test.html

The question is that the above rewrite script give me a 500 internal error. How do I achieve what I want to do?

EDIT:

I see this error in the error log:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断桥再见 2025-01-05 10:00:56

也许存在斜线问题。尝试一下:

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 指令]

Maybe there's a slash problem. Try this:

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

If it doesn't work try:

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

If you want to change only letters and numbers (e.g. wwW.site.com/abdd0456 but not www.site.com/afdf/sdqfsd) then do something like:

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

[Edit: add the L directive]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文