调试.htaccess语法错误

时间:2015-06-30 05:25:10

标签: .htaccess mod-rewrite syntax server

我有以下代码:

# Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^salom.dev[nc]
RewriteRule ^(.*)$ http://www.salom.dev/$1 [r=301,nc]

# 301 Redirect Entire Directory
RedirectMatch 301 /admin(.*) /vendor/aheinze/cockpit/$1

# Change default directory page
DirectoryIndex /site

# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

# Prevent directory listings
Options All -Indexes

我一直有500个错误,但我找不到任何想法的问题?

这是conf文件:

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        ServerName salom.dev

        DocumentRoot /home/otis/Developer/salom
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /home/otis/Developer/salom/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

还有一种方法可以使用开发工具或可能的日志来调试这些错误吗?

1 个答案:

答案 0 :(得分:2)

DirectoryIndex是一个文件而不是目录,并且在[nc]之前缺少空格。

试试这个.htaccess:

# Change default directory page
# DirectoryIndex /site

# Rewrite to www
Options +FollowSymLinks -Indexes
RewriteEngine on

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

# 301 Redirect Entire Directory
RewriteRule ^admin(.*) /vendor/aheinze/cockpit/$1 [L,NC,R=301]

# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>