2015-09-17 110 views
1

我的文件夹结构如下所示: domain.com/html/page.html.htaccess - 隐藏文件夹和.html

如果我点击页面上的链接,我希望网址看起来像这样:domain.com/page

我尝试了不同的.htaccess片段,但没有任何工作方式我想要的。目前你可以访问domain.com/html/page,你会看到正确的页面,但是如果你点击一个链接,URL是domain.com/html/page.html

我的.htaccess:

Options -MultiViews 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /$1.html [QSA,L] 

我希望有人能帮助我,在此先感谢!

回答

3

你可以把这段代码在你的htaccess

Options -MultiViews 
RewriteEngine On 
RewriteBase/

# Redirect /html/some-page.html to /some-page 
RewriteCond %{THE_REQUEST} \s/html/([^/]+)\.html\s [NC] 
RewriteRule^%1 [R=301,L] 

# Rewrite /some-page to /html/some-page.html if it exists 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{DOCUMENT_ROOT}/html/$1\.html -f 
RewriteRule ^([^/]+)$ html/$1.html [L] 
+1

快速和正确的+1 – anubhava

+1

工作,谢谢! – talmo

+0

@talmo不客气 –