Mango Blog 的 URL 重写问题(404 错误)
我正在努力在运行 Apache 2 HTTPD 和 Tomcat 6 以及 Railo 3.1.2 的 Ubuntu 服务器上设置 Mango Blog 的实例。在我开始尝试为博客 URL 实现 URL 重写之前,我能够完成所有设置。
我结合使用了 Adam Tuttle 的 和 John Sieber 的 帖子获取重写规则。我的站点设置如下:
{webroot}/.htaccess
RewriteEngine on
RewriteBase /
# archives rule must be located before page rule for paging to work correctly
RewriteRule archives/(.*)$ archives.cfm/$1 [PT,L,NC]
RewriteRule page/(.*)$ page.cfm/$1 [PT,L,NC]
RewriteRule post/(.*)$ post.cfm/$1 [PT,L,NC]
RewriteRule author/(.*)$ author.cfm/$1 [PT,L,NC]
{apache-home}/sites-enabled/sitename
<VirtualHost *:80>
ServerAdmin *******
DocumentRoot /var/www/******/www
ServerName mango.*****.com
DirectoryIndex index.cfm
<Directory /var/www/*******.com/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error-*******_com.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access-********_com.log combined
ProxyPreserveHost Off
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://********.com:8009/
</VirtualHost>
当我通过访问站点上的 /post/hello-world 来访问博客文章时,出现 404 错误。如果我访问 /post.cfm/hello-world ,该帖子就会正常显示。我针对重写测试器尝试了重写规则,这表明重写应该可以正常工作。我对重写很陌生,所以如果这是简单的事情,我深表歉意。
I am working on setting up an instance of Mango Blog on an Ubuntu Server running Apache 2 HTTPD and Tomcat 6 with Railo 3.1.2. I was able to get everything setup until I started trying to implement URL rewriting for the blog URLs.
I used a combination of Adam Tuttle's and John Sieber's posts to get the rewrite rules. I have the site setup as follows:
{webroot}/.htaccess
RewriteEngine on
RewriteBase /
# archives rule must be located before page rule for paging to work correctly
RewriteRule archives/(.*)$ archives.cfm/$1 [PT,L,NC]
RewriteRule page/(.*)$ page.cfm/$1 [PT,L,NC]
RewriteRule post/(.*)$ post.cfm/$1 [PT,L,NC]
RewriteRule author/(.*)$ author.cfm/$1 [PT,L,NC]
{apache-home}/sites-enabled/sitename
<VirtualHost *:80>
ServerAdmin *******
DocumentRoot /var/www/******/www
ServerName mango.*****.com
DirectoryIndex index.cfm
<Directory /var/www/*******.com/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error-*******_com.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access-********_com.log combined
ProxyPreserveHost Off
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://********.com:8009/
</VirtualHost>
When I visit blog posts by going to /post/hello-world on the site I get a 404 error. If I go to /post.cfm/hello-world the post comes up just fine. I tried the rewrite rules against a rewrite tester, and that said that the rewrites should work fine. I am very new to rewriting, so I apologize if this is something simple.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
放入您的 .htaccess 文件:
Put in your .htaccess file:
尝试将重写规则移至 VirtualHost 块。我遇到了奇怪的问题,.htaccess 在重写时无法正常工作。
我在这里可能是错的,但这就是我认为发生的事情。
Apache 将查找不存在的 /post/ 并返回 404。如果 /post/ 中存在,它将运行 .htaccess,但事实并非如此。
如果重写规则位于 httpd.conf 文件中 VirtualHost 块内的 Directory 块中,则 Apache 知道要重定向而不是查找 /post/。
Try moving your rewrite rules to the VirtualHost block. I've had weird problems with .htaccess not working correctly w/ rewrites.
I could be wrong here, but this is what I think happens.
Apache is going to look for /post/, which doesn't exist and return the 404. It'd run .htaccess if it existed in /post/, but it doesn't.
If the rewrite rules are in your Directory block inside the VirtualHost block in httpd.conf file, then Apache knows to redirect instead of looking for /post/.
您的问题可能与您的 RewriteBase 有关。当我将您的示例加载到测试服务器上时,我在 Apache 的错误日志中看到,由于我使用的环境,使用 RewriteBase 对我来说很有效;但是,在您的情况下使用 / 可能无法创建正确的路径。
在 Web 服务器错误日志中,查看当显示找不到 404 错误时正在生成的路径。它可能会这样说:
按照路径确保它实际上引导您到达 *.cfm 文件所在的实际服务器位置。然后只需修改您的 RewriteBase 使其成为正确的路径即可。
希望有帮助。
Your problem could be related to your RewriteBase. When I loaded your example onto a test server, I saw in Apache's error logs that using the RewriteBase was working for me because of the environment I was using; however, using / in your case might not be creating the correct path.
In your web server error logs, see what path is being generated when it says it can't find the 404 error. Likely, it will say something like:
Follow the path to make sure it's actually leading you to the actual server location where the *.cfm files reside. Then just modify your RewriteBase to make it the right path.
Hope that helps.