例如,如果用户请求/nonexistentdirectory
,那么如何将匹配重定向到/hits.php?d=nonexistentdirectory
?
我在apache.conf中尝试了以下代码;但是,它正在回复错误代码:
<Directory /var/www/>
RewriteEngine On
# No redirect, if file or directory exists
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ link/index.php?a=$1 [L]
</Directory>
错误代码:
Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden
所有建议都表示赞赏!
答案 0 :(得分:2)
您必须启用FollowSymLinks
选项。
<Directory /var/www/>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^/?([^/]+)/?$ link/index.php?a=$1 [L]
</Directory>