将url中的掩码文件夹归档到其他位置

时间:2015-04-28 12:10:27

标签: regex apache .htaccess mod-rewrite

.htaccess中有没有办法让网址看起来像www.example.com/one而不是找一个名为one的文件夹并在其中找到index.html文件,只需要服务器one.html in根文件夹?我一直在努力寻找答案,但如果有可能的话,我不确定会叫什么。

1 个答案:

答案 0 :(得分:0)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On
RewriteBase /

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# always serve one/two/three.html
RewriteRule ^([^./]+)/?$ $1.html [L]