2015-09-17 107 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不客氣 –