我正在尝试重定向以下网址...
www.example.com/test/test2/test3/file.html
.htaccess 文件是www.example.com/change/file
什么,因为我对此不太了解。
我正在尝试重定向以下网址...
www.example.com/test/test2/test3/file.html
.htaccess 文件是www.example.com/change/file
什么,因为我对此不太了解。
也许这会起作用:
# Start the rewrite engine
RewriteEngine On
# Assume the base is root and there are no alias
RewriteBase /
# Prevent loops if the directory exists
RewriteCond %{REQUEST_FILENAME} !-d
# Make sure there is an html file in the URL and capture it's filename if so.
RewriteCond %{REQUEST_URI} ([^/]+)\.html/? [NC]
# Use only the filename as target directory.
RewriteRule .* %1 [L,R=301]
标志 [L,R=301] 的意思是最后一条规则,它是永久重定向。R=301
如果您希望它是临时的,请更改为 302,如果您想要静默映射,请删除整个标志。
更新
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ([^/]+)\.html/? [NC]
RewriteRule .* change/%1 [R=301,L]
# Second rule set
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ([^/]+)/? [NC]
RewriteRule .* %1/%1.html [L]
永久重定向此
http://www.example.com/test/test2/test3/file.html
到
http://www.example.com/change/file
, 有一张无声的地图
http://www.example.com/change/file/file.html