1

次のURLをリダイレクトしようとしています...

www.example.com/test/test2/test3/file.html 

www.example.com/change/file 私はこれについてあまり考えていないので、.htaccessファイルになるものに。

4

1 に答える 1

2

多分これはうまくいくでしょう:

# 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]は、最後のルールであり、永続的なリダイレクトであることを意味します。一時的なものにする場合は302に変更しR=301、サイレントマッピングが必要な場合はフラグ全体を削除します。

更新しました

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

于 2013-01-18T07:58:56.563 に答える