Reputation: 75
I want to make seo friendly url using .htaccess no .php or html extention. Also auto redirect to https://www end URL with a trailing slash.
I have php page: - index.php - product.php - about.php - contact.php - network.php
Final access i want like https:// www.mydomain.com/product/
Webserver apache 2.4.6
I try but image, css, js, font, other php/html file not working
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]
Thank you all in advance.
Upvotes: 1
Views: 70
Reputation: 41229
You can this rule to remove .php and to enforce https on your 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]
To fix your css, js and other relative resources, just add the following base tag to head section of your webpage
<base href="/">
Upvotes: 0