简体   繁体   English

htaccess URL重写-根目录到子文件夹(具有相同名称的文件夹)

[英]htaccess URL Rewrite - Root to Subfolder (with folder of the same name)

I have a file at www.domain.com/blog/blog.html that I want to rewrite as www.domain.com/blog. 我在www.domain.com/blog/blog.html上有一个文件要重写为www.domain.com/blog。

I have figured out the rewrite for removing the extension .html but am having either circular issues or end up pointing the blog rewrite to the blog folder when trying to do the above. 我已经找到用于删除扩展名.html的重写,但是遇到循环问题或最终在尝试执行上述操作时将博客重写指向博客文件夹。

I am new to rewrite syntax, so help would be much appreciated! 我是新来重写语法的人,所以将不胜感激!

Create /blog/.htaccess if it doesn't already exist and place this rule: 创建/blog/.htaccess如果尚不存在)并放置以下规则:

RewriteEngine On
RewriteBase /blog/

RewriteRule ^/?$ blog.html [L]

# To internally forward /blog/file to /blog/file.html
RewriteCond %{DOCUMENT_ROOT}/blog/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ $1.html [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM