对不起,我不知道我在做什么,我需要你的帮助。 我有一个htaccess文件,做一些URL重写,但它不能在服务器上工作。 我不认为mod_rewrite被启用。 但没有注释掉,phpinfo()表示它是启用的模块之一。
我不知道该怎么办。 请帮忙!
从我的.htaccess文件中:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
更新:我在http.conf中把这一行从none改为all:
# AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All
我救了它。 试图重新启动Apache(通过做我的IT人说:/ sbin /服务httpd重新启动),但Apache无法重新启动说:
Stopping httpd: [FAILED] Starting httpd: [FAILED] (98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs
现在我不能回滚因为我得到相同的信息…什么是错的!
您需要在位置,VirtualHost或.htaccess中的特定区域启用mod_rewritefunction。 你可以这样做
RewriteEngine on RewriteRule ^oldstuff\.html$ newstuff.html
通过使用RewriteLog和RewriteLogLevel选项打开日志,你可以看到模块正在做什么:
RewriteLog "/var/log/apache/rewrite.log" RewriteLogLevel 2
日志级别上升到9,但文件警告不要超过2生产。 我build议您在完成debugging后将其彻底closures。
您可以在mod_rewrite文档中find更多信息。
看到您的使用情况后,您似乎在尝试将不存在的项目发送到index.php。 你可以做类似的事情,而不使用mod_rewrite:
ErrorDocument 404 http://this.server/path/index.php
这会将用户redirect到index.php,并要求您对位置进行硬编码,这可能并不理想。
或者,我build议反转你的条件的意义,并删除第一个RewriteRule。 “如果请求不是一个文件,不是一个链接,不是一个目录,然后redirect到index.php”。 这将使你的规则更简单。 你也可以从你的RewriteRules中丢失[NC]标志,因为它没有任何作用。
RewriteEngine On RewriteCond ! %{REQUEST_FILENAME} -s RewriteCond ! %{REQUEST_FILENAME} -l RewriteCond ! %{REQUEST_FILENAME} -d RewriteRule ^.*$ index.php [L]
(我没有检查这个工作)
重新启动Apache服务器?