2013-01-18 4 views

Répondre

2

Peut-être que cela fonctionnera:

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

Drapeaux [L, R = 301] La moyenne est la dernière règle et il est une redirection permanente. Changez en 302 si vous voulez qu'il soit temporel et supprimez le drapeau entier R=301 si vous voulez un mapping silencieux.

MISE À JOUR

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] 

Redirige définitivement ce

http://www.example.com/test/test2/test3/file.html à

http://www.example.com/change/file, avec une carte silencieuse

http://www.example.com/change/file/file.html

+0

pouvez-vous expliquer un peu plus j'ai moins d'idée en elle? – chanz

+0

Bien sûr. Je le ferai dans la réponse. –

+0

@chanz l'a fait. - –

Questions connexes