Voglio creare un URL seo friendly usando .htaccess senza estensione .php o html. Anche il reindirizzamento automatico a https://www URL finale con una barra finale.
Ho una pagina php: - index.php - product.php - about.php - contact.php - network.php
Accesso finale che desidero https: // www.mydomain.com/product/
Webserver apache 2.4.6
Provo ma image, css, js, font, altri file php / html non funzionano
RewriteEngine On
# Remove file extensions, add a trailing slash.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
Grazie a tutti in anticipo.
risposte:
0 per risposta № 1Puoi questa regola per rimuovere .php e imporre https su Apache 2.4
RewriteEngine on
RewriteCond %{HTTPS}#%{HTTP_HOST} ^off#(?:www.)?(.+)$
RewriteRule ^ https://www.%1%{REQUEST_URI} [NE,L,R]
#remove .php
RewriteRule ^(.+).php$ /$1/ [L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [END]
Per correggere i tuoi css, js e altre risorse relative, basta aggiungere il seguente tag di base alla sezione head della tua pagina web
<base href="/">