mod_alias规则:
/water /local/path1/water
目标网址:
http://www.mysite.com/water/css/style.css
http://www.mysite.com/water/js/java.js
实际网址:
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
未找到或无法启动
答案 0 :(得分:0)
1。我没有太多使用mod_alias的经验..但我认为您通过重写/local/path1/water/
做错了 - mod_rewrite会重写URL,所以它应该是URL在这里。
2。我将假设/local/path1/water%{REQUEST_URI}
是正确的构造,它引用了正确的文件。但是......你只将它们(这两个条件)应用于第一个重写规则......
3. 据我所知,这些规则放在服务器配置/ VirtualHost上下文中,而不是放在.htaccess中。
把所有这些放在一起你应该试试这个:
RewriteEngine on
RewriteCond /local/path1/water%{REQUEST_URI} !-d
RewriteCond /local/path1/water%{REQUEST_URI} !-f
RewriteRule ^/water/css/([^/]+\.css)$ /water/css.php?src=$1 [L,PT]
RewriteCond /local/path1/water%{REQUEST_URI} !-d
RewriteCond /local/path1/water%{REQUEST_URI} !-f
RewriteRule ^/water/js/([^/]+\.js)$ /water/js.php?src=$1 [L,PT]