1

看起来这里有很多关于 RewriteRules、相对路径和在不更改 URL 的情况下重定向的问题 - 但是,在我的所有搜索中,它们似乎都没有回答我的具体情况。

这是我当前的 .htaccess 文件:

 RewriteEngine On

 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-l
 RewriteCond {REQUEST_FILENAME} !^images
 RewriteRule ^files(.*)$ ../../fileManager/server/php/files$1 [L]

基本上这样做是,如果某人输入的 URL 在根目录之后包含单词“files”,那么它会将它们重定向到两个目录的路径,该路径实际上包含该文件。

例如,如果您访问“ http://www.example.com/files/username/myImage.jpg ”,它实际上会将您重定向到“ http://s281192971.onlinehome.us/cms/fileManager/server/ php/文件/用户名/myImage.jpg “。

这样做的问题是它在本地工作得很好,但是当我将它上传到我的服务器时,它就停止工作了。

我发现的一种方法是只指定文件路径的绝对路径,如下所示:

 RewriteRule ^files(.*)$ http://s281192971.onlinehome.us/cms/fileManager/server/php/files$1 [L]

这“有效”——但问题是,它也改变了 URL。我宁愿保留用户输入的 URL(http://www.example.com/files/username/myImage.jpg),而不是绝对路径。

这可能吗?

4

1 回答 1

1

我没有尝试过,但文档声明您可以使用 URL 路径进行替换。

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

我的猜测是让你的规则像:

RewriteRule ^cms/mysite/files(.*)$ /fileManager/server/php/files$1 [L]
于 2013-03-14T12:52:43.007 回答