目前,我网站的用户可以使用以下网址架构访问文件:
http://www.example.com/dwl/download.php?file=/files/index.rar
现在我希望他们可以使用以下架构访问它:
http://www.example.com/dwl/content/files/index.rar
download.php文件位于dwl目录中。
我尝试了以下.htaccess:
RewriteEngine On
RewriteRule ^file/([^/]*)$ download.php?file=$1 [L]
但是当我尝试它时,我得到了404错误 有人可以帮我写一下正确的.htaccess-Entry吗?
答案 0 :(得分:1)
如果您想从http://www.example.com/dwl/download.php?file=/files/index.rar
重定向到http://www.example.com/dwl/content/files/index.rar
,则需要:
RewriteRule ^/dwl/download.php?file=/(.*) /dwl/content/$1 [L]
答案 1 :(得分:0)
我认为您必须使用的代码如下:
RewriteEngine On
RewriteRule ^/dwl/content(/files/[^/]*)$ /dwl/download.php?file=$1
答案 2 :(得分:0)
通过httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在.htaccess
目录下的DOCUMENT_ROOT/dwl
中:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /dwl/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+dwl/download\.php\?file=([^\s&]+) [NC]
RewriteRule ^ content/%1? [R=301,L]
RewriteRule ^content/(.+)$ download.php?file=$1 [L,QSA,NC]