开发者

.htaccess modification

开发者 https://www.devze.com 2023-01-27 19:52 出处:网络
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 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?开发者_Go百科? Any Idea??


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


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消