2013-12-15 70 views
1

我想從/page.html重定向到/page子目錄內,但它不起作用。重定向/page.html到/頁面不起作用子目錄內

  • 我做什麼:http://example.com/subdirectory/page.html
  • 我能得到什麼:http://example.com/page
  • 我想要什麼:http://example.com/subdirectory/page

.htacces文件:

RewriteEngine On 

#example.com/page will display the contents of example.com/page.html 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+)$ $1.html [L,QSA] 

#301 from example.com/page.html to example.com/page 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/ 
RewriteRule ^(.*)\.html$ /$1 [R=301,L] 

我該如何得到這個工作?

回答

1

使用此代碼.html躲在你DOCUMENT_ROOT/.htaccess文件:

Options +FollowSymLinks -MultiViews 
RewriteEngine On 

RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC] 
RewriteRule^/%1 [L,NC,R=301] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+?)/?$ /$1.html [L] 
0

試試這個:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^([^\.]+)$ $1.html [NC,L] 
</IfModule> 
  • 感謝
相關問題