aslamdoctor
aslamdoctor

Reputation: 3935

How to add .php extension using .htaccess url rewriting?

I have set up .htaccess file on my website which display SLUG text as page name in URL but without extension. e.g. Real url is

www.mywebsite.com/page.php?page=about-us

Then it loads on below url through url rewriting

www.mywebsite.com/about-us

Below is my .htaccess file code

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^.*(images/|\.js|\.css).*$ [NC]
RewriteRule ^([a-zA-Z0-9_-]+)$ /page.php?page=$1

Now I want to show the .php extension on all pages, so that the urls should be like below

www.mywebsite.com/about-us.php

How can I do this ?

Upvotes: 2

Views: 3158

Answers (2)

Talha Sahi
Talha Sahi

Reputation: 19

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

php_flag display_errors on

Upvotes: 0

David Frank
David Frank

Reputation: 6092

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^.*(images/|\.js|\.css).*$ [NC]
RewriteRule ^([a-zA-Z0-9_-]+)\.php$ /page.php?page=$1

Upvotes: 2

Related Questions