使 mod_alias 与 mod_rewrite 一起使用
mod_alias 规则:
/water /local/path1/water
目标 URL:
http://www.mysite.com/water/css/style.css
http://www.mysite.com/water/js/java.js
实际 URL:
http://www.mysite.com/water/css.php?src=style.css
http://www.mysite.com/water/js.php?src=java.js
Mod 重写规则:
RewriteEngine on
RewriteCond /local/path1/water%{REQUEST_URI} !-d
RewriteCond /local/path1/water%{REQUEST_URI} !-f
RewriteRule ^/water/css/([^/]+)$ /local/path1/water/css.php?src=$1 [PT]
RewriteRule ^/water/js/([^/]+)$ /local/path1/water/js.php?src=$1 [PT]
问题: 它不起作用,我收到 404 错误,错误显示如下 脚本 /www/mysite.com/htdocs/css.php
未找到或无法启动
mod_alias rule:
/water /local/path1/water
Target URLs:
http://www.mysite.com/water/css/style.css
http://www.mysite.com/water/js/java.js
Actual URLs:
http://www.mysite.com/water/css.php?src=style.css
http://www.mysite.com/water/js.php?src=java.js
Mod rewrite rule:
RewriteEngine on
RewriteCond /local/path1/water%{REQUEST_URI} !-d
RewriteCond /local/path1/water%{REQUEST_URI} !-f
RewriteRule ^/water/css/([^/]+)$ /local/path1/water/css.php?src=$1 [PT]
RewriteRule ^/water/js/([^/]+)$ /local/path1/water/js.php?src=$1 [PT]
Problem: it's not working and I am getting 404 errors and the error says this
script /www/mysite.com/htdocs/css.php
not found or unable to start
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1. 我没有太多使用 mod_alias 的经验..但我认为你重写
/local/path1/water/
是错误的 - mod_rewrite 进行 URL 重写,所以这里也应该是 URL。2. 我假设
/local/path1/water%{REQUEST_URI}
是正确的构造,并且它引用了正确的文件。但是...您仅将它们(这两个条件)应用于第一个重写规则...3. 据我了解,这些规则放置在服务器配置/VirtualHost 上下文中,而不是放置在 .htaccess 中。
把所有这些放在一起你应该尝试这个:
1. I do not have much experience working with mod_alias .. but I think you are doing wrong by rewriting to
/local/path1/water/
-- mod_rewrite does URL rewriting, so it should be URL here as well.2. I will assume that
/local/path1/water%{REQUEST_URI}
is correct construction and it references correct file. But ... you apply them (these 2 conditions) to a first rewrite rule only ...3. As I understand these rules are placed in server config / VirtualHost context and not in .htaccess.
Taking all this together you should try this instead: