Linux Apache mod_rewrite

好吧,在这里! 即时运行的Linux(cent os),我的httpd.conf文件中有“LoadModule rewrite_module modules / mod_rewrite.so”启用! “mod_rewrite.so”位于modules文件夹中。 这里是一些代码

HTTPD.CONF:

<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 

我希望我提供了enuph信息.. thx提前任何帮助!

要在.htaccess文件中启用mod_rewrite,您需要在.htaccess文件所在的目录中允许覆盖FileInfo 。

如果在.htaccess中只有“RewriteEngine on”,那么只需将其删除即可,因为它已经在vhostconfiguration中,所以完全没有用处。
如果您需要在这个.htaccess文件中添加其他RewriteCond / RewriteRule,则必须为/home/.sites/70/site4/web/目录添加AllowOverride FileInfo指令。

 <Directory /home/.sites/70/site4/web> AllowOverride FileInfo </Directory>