2012-04-03 18 views
0

Ich habe einen Code 301-Weiterleitung Seiten wie dies in .htaccess-Datei zu finden versucht:Wie .htaccess umleiten Urls .html

www.example.com/view-profiles

Um

www.example.com/view-profiles.html

Aber ich muss sicherstellen, dass es nicht mit der /index.html Umleitungsregel, die ich dort habe und auch in der Regel auf viele URLs gleichzeitig angewendet werden könnte .

Vielen Dank im Voraus für Ihre Hilfe !!

Antwort

0

Haben Sie das versucht?

redirect 301 /view-profiles http://www.example.com/view-profiles.html 
0

Wenn Sie alle Dateien haben wollen, die eine Erweiterung .html haben das Ziel einer solchen Umleitung zu sein, müssen Sie mod_rewrite

Dies ist nicht getestet verwenden!
Zum Testen empfehle ich, zuerst den 301 durch einen 302 zu ersetzen, da sich Ihr Browser vielleicht an die 301 Einstellung erinnert und nicht auf den Server zum Umschreiben zugreifen kann.

In .htaccess müssen Sie so etwas wie dieses

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    # If in subdirectory uncomment the following and 
    # replace subdir with your subdirectory 
    #Rewritebase /subdir 

    # This will rewrite if request_filename is not a directory (!-d) 
    RewriteCond %{REQUEST_FILENAME} !-d 

    # RewriteCond is with AND per default 
    # Only if request + .html extension is a file (-f) 
    RewriteCond %{REQUEST_FILENAME}.html -f 

    # If both above conditions are true this rule is followed 
    # ^(.*)$: Regular Expression Match everything `.*` in the request 
    # from start `^` to the end `$` 
    # Brackets mean: capture the text if matched 
    # $1.html Append .html to the captured text from the Rule 
    # [L,R=301]: L=Last don't try to rewrite any other rule that comes below 
    #   R=301 Redirect and set the HTTP Status code to 301 
    RewriteRule ^(.*)$  $1.html  [L,R=301] 

</IfModule> 

wieder! Dies ist nicht getestet!

0

Wenn Sie nur Regel für/view-profiles` URI dann wird es funktionieren:

RewriteRule ^view-profiles/?$ view-profiles.html [L,NC,R=301]