我是网络开发的新手。
下面的Htaccess代码在根目录文件中工作正常。我们尝试重写子文件夹/test/downloadh.php中的文件。当我在代码下面更改时,我们无法获得根文件链接不起作用。
RewriteEngine on
RewriteBase /test/
请您建议我们,如何获取网址
http://example.com/test/downloadh/the-house-on-the-borderland
到
http://example.com/test/downloadh.php?id=the-house-on-the-borderland
工作守则: -
# disable directory browsing
Options -Indexes
AddDefaultCharset UTF-8
FileETag MTime Size
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+album\.php\?Id=([^\s&]+) [NC]
RewriteRule ^ album/%1? [R=301,L]
RewriteRule ^album/([^/]+)/?$ album.php?Id=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([^\s&]+) [NC]
RewriteRule ^ download/%1? [R=301,L]
RewriteRule ^download/([^/]+)/?$ download.php?id=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+downloada\.php\?linkb=([^\s&]+) [NC]
RewriteRule ^ downloada/%1? [R=301,L]
RewriteRule ^downloada/([^/]+)/?$ downloada.php?linkb=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:downloadb\.php)?\?mlink=([^\s]+)&linkb=([^\s]+)? [NC]
RewriteRule ^ downloadb/%1%2? [R=301,L]
RewriteRule ^downloadb/([^/]+)/([^/]+)/?$ downloadb.php?mlink=$1&linkb=$2 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:songs\.php)?\?id=([^\s]+)&linkb=([^\s]+)? [NC]
RewriteRule ^ songs/%1/%2? [R=301]
RewriteRule ^songs/([^/]+)/([^/]+)/?$ songs.php?id=$1&linkb=$2 [L,QSA]
# CUSTOM ERRORPAGE
ErrorDocument 401 /error/test.php
ErrorDocument 403 /error/test.php
ErrorDocument 404 /error/test.php
ErrorDocument 500 /error/test.php
错误代码: -
RewriteCond %{THE_REQUEST} /downloadh(?:\.php)?\?id=([^\s&]+)\s [NC]
RewriteRule ^ downloadh/%1/? [R=302,L,NE]
RewriteRule ^downloadh/([^/]+)/?$ downloadh.php?id=$1 [NC,L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /test/downloadh.php\?id=([^\s&]+) [NC]
RewriteRule ^test/downloadh\.php /%1? [R=301,L,NE]
RewriteRule ^downloadh/([^/]+)/?$ /test/downloadh.php?id=$1 [L,QSA]
答案 0 :(得分:0)
试试这段代码:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(test/downloadh)\.php\?id=(.+)\sHTTP.*$ [NC]
RewriteRule ^ %1/%2? [L,R=301]
RewriteRule ^test/downloadh/([^/]+)/?$ test/downloadh.php?id=$1 [L]