好的,开始吧!我正在运行 linux(cent os),我的 httpd.conf 文件启用了“LoadModule rewrite_module modules/mod_rewrite.so”行!“mod_rewrite.so”位于模块文件夹中。以下是一些代码
HTTPD.配置文件:
<Directory />
Options All
AllowOverride All
</Directory>
<Directory "/var/www/html">
Options Indexes All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
VHost 文件:
# owned by VirtualHost
NameVirtualHost 192.168.10.200:80
# FrontPage needs the following four things to be here
# otherwise all the vhosts need to go in httpd.conf, which could
# get very large since there could be thousands of vhosts
ServerRoot /etc/httpd
<VirtualHost 192.168.10.200:80>
ServerName www.site.com
ServerAlias site.com
ServerAdmin admin
DocumentRoot /home/.sites/70/site4/web
ErrorDocument 401 /error/401-authorization.html
ErrorDocument 403 /error/403-forbidden.html
ErrorDocument 404 /error/404-file-not-found.html
ErrorDocument 500 /error/500-internal-server-error.html
RewriteEngine on
RewriteCond %{HTTP_HOST} !^192.168.10.200(:80)?$
RewriteCond %{HTTP_HOST} !^www.site.com(:80)?$ [NC]
RewriteRule ^/(.*) http://www.site.com/$1 [L,R]
# BEGIN WebScripting SECTION. DO NOT EDIT MARKS OR IN BETWEEN.
AddHandler cgi-wrapper .cgi
AddHandler cgi-wrapper .pl
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .php
# END WebScripting SECTION. DO NOT EDIT MARKS OR IN BETWEEN.
RewriteOptions inherit
#AliasMatch ^/~([^/]+)(/(.*))? /home/.sites/70/site4/users/$1/web/$3
Include /etc/httpd/conf/vhosts/site4.include
# BEGIN Bandwidth SECTION. DO NOT EDIT MARKS OR IN BETWEEN.
# END Bandwidth SECTION. DO NOT EDIT MARKS OR IN BETWEEN.
# BEGIN PHP SECTION. DO NOT EDIT MARKS OR IN BETWEEN.
php_admin_flag safe_mode On
php_admin_flag safe_mode_gid Off
php_admin_value safe_mode_allowed_env_vars PHP_
php_admin_value safe_mode_exec_dir .
php_admin_value safe_mode_include_dir .
php_admin_value safe_mode_protected_env_vars LD_LIBRARY_PATH
php_admin_flag register_globals On
php_admin_flag allow_url_fopen Off
php_admin_flag allow_url_include Off
php_admin_value open_basedir /home/:/tmp/:/var/lib/php/session/:/home/.sites/70/site4/
php_admin_value post_max_size 20M
php_admin_value upload_max_filesize 20M
php_admin_value max_execution_time 120
php_admin_value max_input_time 60
php_admin_value memory_limit 16M
# END PHP SECTION. DO NOT EDIT MARKS OR IN BETWEEN.
</VirtualHost>
# end of VirtualHost owned section
VHost 包含文件:
# /etc/httpd/conf/vhosts/site4.include
# user customizations can be added here.
.htaccess 文件:
Options -Indexes
RewriteEngine on
无论我怎么尝试,我都会得到:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
这里是 Apache 日志:
/home/.sites/70/site4/web/.htaccess: RewriteEngine not allowed here
我希望我提供了足够的信息..提前感谢任何帮助!
答案1
要在 .htaccess 文件中启用 mod_rewrite,您需要允许覆盖 FileInfo在 .htaccess 文件所在的目录中。
如果您在 .htaccess 中只有“RewriteEngine on”,则只需将其删除即可,因为它已经在 vhost 配置中,因此完全没用。
如果您需要在此 .htaccess 文件中添加其他 RewriteCond/RewriteRule,则必须为 /home/.sites/70/site4/web/ 目录添加 AllowOverride FileInfo 指令。
<Directory /home/.sites/70/site4/web>
AllowOverride FileInfo
</Directory>