2017-05-07 36 views
0

我在Apache的配置設置爲允許mod_rewrite的:Apacher mod_rewrite - 如何讓乾淨的URL與.html?

<Directory /var/www/> 
    Options Indexes FollowSymLinks 
    AllowOverride None 
    AllowOverride All 
</Directory> 

$ sudo a2enmod rewrite 
$ service apache2 restart 

但爲什麼我用的.html網址將無法正常工作?例如:

mysite.com/about.html 
mysite.com/contact.html 

,但它的工作原理:

mysite.com/about 
mysite.com/contact 

我怎麼能有的.html工作,以及網址嗎?

編輯:

這是的.htaccess(鏌鋣):

# For full documentation and other suggested options, please see 
# http://rtfm.modx.com/evolution/1.0/administration/friendly-url-solutions 
# including for unexpected logouts in multi-server/cloud environments 
# and especially for the first three commented out rules 

#php_flag register_globals Off 
AddDefaultCharset utf-8 
#php_value date.timezone Europe/Moscow 

#Options +FollowSymlinks 
RewriteEngine On 
RewriteBase/

# Fix Apache internal dummy connections from breaking [(site_url)] cache 
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC] 
RewriteRule .* - [F,L] 

# Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin 
#RewriteCond %{HTTP_HOST} !^$ 
#RewriteCond %{HTTP_HOST} !^www\. [NC] 
#RewriteCond %{HTTP_HOST} (.+)$ 
#RewriteRule ^(.*)$ http://www.%1/$1 [R=permanent,L] . 

# without www 
#RewriteCond %{HTTP_HOST} . 
#RewriteCond %{HTTP_HOST} !^example\.com [NC] 
#RewriteRule (.*) http://example.com/$1 [R=301,L] 

# without www all domains 
#RewriteCond %{HTTP_HOST} . 
#RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC] 
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

# Exclude /assets and /manager directories and images from rewrite rules 
RewriteRule ^(manager|assets)/.*$ - [L] 
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L] 

# For Friendly URLs 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 

# Reduce server overhead by enabling output compression if supported. 
#php_flag zlib.output_compression On 
#php_value zlib.output_compression_level 5 

我看不出有任何的規則有說關於有html的...

+0

什麼?你有一些'.htaccess'工作或有一些規則定義了一些地方,它是模糊的,因爲你不需要mod_rewrite來顯示在URL結尾的擴展名。 –

回答

1

第一件事將這兩個相反的含義指令一個接一個沒有任何意義:

AllowOverride None 
AllowOverride All 

你只需要後期,即:

AllowOverride All 

其次,支持擴展名的網址,你只需要啓用MultiViews選項爲:

Options Indexes FollowSymLinks MultiViews