.htaccess修改

发布于 2024-10-06 07:55:03 字数 368 浏览 0 评论 0原文

我使用直接路径从我的网站下载文件。该链接是这样的

http://www.site.com /download.php?dir1/dir/dir3/file.doc

我想用 mod 重写规则包装它,以便只显示下面的链接

http://www.site.com/download

文件,dir 和 dir3 是变量。 我要在 .htaccess 文件中做什么?有什么想法吗?

I am using direct paths for downloading files from my site. the link is something like this

http://www.site.com/download.php?dir1/dir/dir3/file.doc

i want to wrap it with mod rewite rules so that only below link should be appeared

http://www.site.com/download

file, dir and dir3 are variable.
what i'hv to do in my .htaccess file?? Any Idea??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

月光色 2024-10-13 07:55:03

一个简单的重定向是:

RewriteRule ^http://www.site.com/download/(.*)/?$ http://www.site.com/download.php?dir1/dir/dir3/$1 [NC,L] 

这将接受对“人工”下载目录中某些内容的任何请求,并将其路由到真实位置。

您可以根据您的需要添加更复杂的规则,去除文件类型等,或者将“名称”重定向到文件名等。

例如:

RewriteRule ^http://www.site.com/download/pdf/(.*)/?$ http://www.site.com/download.php?dir1/dir/dir3/$1.pdf [L,NC]

这将有一个包含文件名(扩展名)的人工 PDF 文件夹,路由到 .pdf 文档....您可以按照您喜欢的任何方式塑造重定向...取决于您喜欢的格式

A simple redirect would be:

RewriteRule ^http://www.site.com/download/(.*)/?$ http://www.site.com/download.php?dir1/dir/dir3/$1 [NC,L] 

This will take any request for something in the 'artificial' download directory and route it to the real location.

You can add more complex rules stripping out filetypes etc depending on your needs, or redirecting a 'name' to a filename etc etc..

e.g:

RewriteRule ^http://www.site.com/download/pdf/(.*)/?$ http://www.site.com/download.php?dir1/dir/dir3/$1.pdf [L,NC]

This would have an artificial PDF folder containing a filename ex the extension, routing to a .pdf doc....you can shape the redirect any way you like really...depends on the format you prefer

┈┾☆殇 2024-10-13 07:55:03

不是具体问题。 dir1/dir/dir3/file.doc 是什么意思?如果您想获取http://www.site.com/download.php?dir1/dir/dir3/file.doc,当您访问http://www.site .com/download 在 .htaccess 文件中执行接下来的操作。

RewriteEngine on
RewriteRule ^download/(.*)/?$ download.php?dir1/dir/dir3/file.doc [L]

Not specific question. What is dir1/dir/dir3/file.doc means? If you want to get http://www.site.com/download.php?dir1/dir/dir3/file.doc, when you go to http://www.site.com/download do the next things in your .htaccess file.

RewriteEngine on
RewriteRule ^download/(.*)/?$ download.php?dir1/dir/dir3/file.doc [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文