2

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 ?

3
  • Why would you want the .php extension. The url looks much cleaner without it. It's also better for SEO. Commented Jan 10, 2012 at 13:42
  • ya u r right but my seo is not understanding it. he wants pages with .php extension :P Commented Jan 11, 2012 at 7:22
  • Just tell him it will hurt his page ranking in search engines. Only slightly, but at least you are not lying to the man. Commented Jan 11, 2012 at 15:36

2 Answers 2

2
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^.*(images/|\.js|\.css).*$ [NC]
RewriteRule ^([a-zA-Z0-9_-]+)\.php$ /page.php?page=$1
Sign up to request clarification or add additional context in comments.

1 Comment

Works okay on my test-server. Please recheck the code, as the change David made to your original should not cause a 500 error.
0
RewriteEngine On

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

php_flag display_errors on

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.