2017-09-19 1 views
0

Comment puis-je supprimer www de mon URL et forcer https et supprimer .html tous en même temps?supprimer www et html tout en forçant https

RewriteEngine on 

# force ssl 
RewriteCond  %{SERVER_PORT} ^80$ 
RewriteRule  ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] 

# Remove .html 
RewriteCond  %{REQUEST_FILENAME}.html -f 
RewriteRule  ^(.+?)/?$ $1.html [L] 

Répondre

0

Essayez d'ajouter ce qui suit à votre .htacces au lieu de votre code ci-dessus.

RewriteEngine on 

#Force HTTPS. 
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] 
RewriteCond %{HTTPS} !on 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

# Start rewrite. 
RewriteBase/

# Load page without extension. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+)$ $1.html [L,QSA] 

# 301 While Rewrite. 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/ 
RewriteRule ^(.*)\.html$ /$1 [R=301,L] 

# Handle Trailing Slashes. 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/$ $1 [R,L] 

# Rewrite rule to add .html extension back internally. 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+[^/])$ $1.html 

Cela se traduira par http://www.example.com/test.html à manipuler par le navigateur https://example.com/test lors du chargement encore le fichier test.html.

+0

une chance que vous pouvez expliquer ce que tout fait? aussi cela fonctionnera-t-il encore si j'entre dans le site Web sans "www"? – nathan

+0

testé avec xampp mais obtenir "Votre connexion n'est pas privée" dans google chrome – nathan

+0

Oui, cela fonctionne aussi si vous allez sur le site sans le ** www **. Avez-vous une configuration XAMPP pour gérer les connexions HTTPS? Ce message apparaîtra si vous ne l'avez pas configuré correctement ou si vous n'avez pas de certificat. –

0

Mettre le code suivant à .htaccess dans le répertoire principal

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule^https://yoursite.com/$1 [L,R] 

#the code above will redirect the entire site into https without www unless the request come with https://www .  

RewriteCond %{HTTP_HOST} ^www\. 
RewriteRule^https://yoursite.com/$1 [L,R] 

#The code above will catch any request with www if passed first code. 

RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.html[\s?/] [NC] 
RewriteRule^/%1%2 [R=302,L,NE] 

#the code above will remove any .HTML. 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.html [NC,L] 

# you can use the two lines if file without extension not work and you want to map them to .html files and if you want to go the same file .html without extension keep it as it is but , If you want to change it to same name .php file , replace $.html in the last line to $.php .