简体   繁体   中英

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.

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.

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:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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