使 mod_alias 与 mod_rewrite 一起使用

发布于 2024-12-03 12:45:18 字数 751 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原来分手还会想你 2024-12-10 12:45:18

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]

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:

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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文