【发布时间】:2014-04-28 18:21:05
【问题描述】:
正如标题所说,当我将它上传到我的服务器 (Ubuntu LTS) 时,我的重写规则不起作用。 .htaccess 文件正在运行,但什么都不做。
mod_rewrite 已加载,我已经验证了几种方法。我尝试在 .htaccess 文件中编写垃圾文本并收到 500 内部错误,因此该文件似乎在循环中。 virtualHost 配置有“allowOverride All”。
.htaccess 文件由一系列重写规则组成,例如:
RewriteRule ^webshop$ index.php?page=webshop [QSA]
RewriteRule ^webshop/([0-9]+)$ index.php?page=webshop&catID=$1 [QSA]
在服务器上,我必须使用虚拟主机、一台公共服务器和一台测试服务器。公共服务器工作正常,所有重写规则都与上述类似并且工作正常。不想玩的就是测试用的虚拟主机。一台服务器,一个 IP,两个 FQDN。
想法?
编辑 - 这是 VirtualHost 配置:
<VirtualHost *:80>
ServerAdmin beta@example.com
ServerName beta.example.com
DocumentRoot /var/www/beta/www-root
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/beta/www-root>
AddDefaultCharset utf-8
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from (Two IPs omitted)
</Directory>
<Directory /var/www/temp>
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.beta.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
【问题讨论】:
-
那是因为您的规则
webshop/([0-9]+)生成了一个虚拟文件夹,您将其转发到当前文件夹中的index.php。要解决您的问题,请使用以下规则:RewriteRule ^webshop/([0-9]+)$ /index.php?page=webshop&catID=$1 [L]。前导斜线表示begin from root。这样,您将其转发到根文件夹中的index.php,而不是您的虚拟文件夹中 -
检查您的服务器配置 - 在您的服务器上必须设置 AllowOverride All(请参阅
http.conf或您的VirtualHost)! -
你能发布虚拟主机吗?
-
@JustinIurman 谢谢,不过没有改变。
-
将“RewriteBase /”放在“RewriteRule”行上方
标签: php .htaccess mod-rewrite