2013-07-10 60 views
0

下面給出的的.htaccess代碼獲取內部錯誤500內部服務器錯誤的.htaccess

RewriteEngine On 

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

RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}example.com$ 
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]example.com$ 
RewriteRule ^$ portfolio/index.php?id=%1 [NC,L] 

AuthType Basic 
AuthName "If your not authenticated , then go seat in corner" 
AuthUserFile /var/www/devRoot/.htpasswd 
Require valid-user 

但如果我只用

AuthType Basic 
AuthName "If your not authenticated , then go seat in corner" 
AuthUserFile /var/www/devRoot/.htpasswd 
Require valid-user 

上面的代碼工作完美。

問題是我不明白爲什麼第一個代碼不工作。

日誌:

[Wed Jul 10 13:12:11 2013] [alert] [client 1.23.112.242] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configur        ation 
[Wed Jul 10 13:12:12 2013] [alert] [client 1.23.112.242] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configur        ation 

解決:

Did you ensure the RewriteEngine is on? 

You'll want to verify that the mod is enabled - just look for rewrite.load symlink in /etc/apache2/mods-enabled. If not, run sudo a2enmod rewrite to enable it. Restart apache using sudo service apache2 restart and provided your .htaccess syntax is correct this will work. 

Otherwise you will need to paste more information about your .htaccess file. 
+0

開始接通調試日誌記錄。然後考慮superuser.com .. –

+0

如何打開調試 – user2568637

回答

0

你還沒有啓用重寫引擎,取消對該行在httpd.conf

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so 

您可能必須在/ etc/apache2/mods-available在這種情況下,只需將其複製到mods-enabled並重啓

這是假設Linux?

窗口你找

LoadModule rewrite_module modules/mod_rewrite.so 
+0

你確定RewriteEngine是否打開? 您需要驗證mod是否已啓用 - 只需在/ etc/apache2/mods-enabled中查找rewrite.load符號鏈接即可。如果沒有,運行sudo a2enmod rewrite啓用它。使用sudo service apache2 restart重新啓動apache,並提供.htaccess語法是正確的,這將起作用。 否則,您需要粘貼更多關於.htaccess文件的信息。 – user2568637