Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
April 23, 2014, 09:15:07 PM

Pages: [1]   Go Down
  Print  
Author Topic: Hide .php extenstion in URL  (Read 18816 times)
mindf1
Newbie
*
Offline Offline

Posts: 4


« on: March 10, 2011, 04:37:05 PM »

Hello, I am wondering how to hide the .php extension from the user so that they don't see it in the URL.

I would like to the use RewriteEngine (or something similar) in my .htaccess file and have it so that it can hide the extensions for all of the files in a directory at once without having to list each one of the files that I would like for this to happen to.

I have tried all of the codes I could find online but none of them have worked.

Can someone please provide me a code that will work with Lunarpages?

Thanks in advance.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5811



« Reply #1 on: March 10, 2011, 07:24:25 PM »

First, are you on a Linux or Windows server? Windows servers (IIS) ignore the .htaccess file -- I believe there is a way to do URL rewriting, but I don't know enough about it to help you. If it's a Linux server (Apache), there are all sorts of things you can do with URL rewriting. Do you want your .php files to pretend to be another extension (e.g., .html), or do you want the extension to disappear completely? That is, if you have file /myfile.php, what do you want the world to see in the address -- /myfile.html or /myfile? The first is easy to do, and is very commonly done to hide the underlying site technology (more to allow you to change from .php to .aspx to .jsp to ... as the mood strikes you, without invalidating bookmarks and search engine indexes, than any kind of real security). The second is possible, but it can be a bit of a problem to keep directories (folders) from being treated as .php files missing their extensions. What are you looking to do? What kinds of things have you tried? If you're using a canned application, does it offer "SEO/SEF/Pretty URLs"?
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
mindf1
Newbie
*
Offline Offline

Posts: 4


« Reply #2 on: March 11, 2011, 06:54:07 PM »

Thanks for your response.

I am on a Linux server running Apache. I do not want my .php files to pretend to be another extension. I want them to disappear completely. (/myfile)

I am not using a canned application. I have built my site from scratch. http://mindfulefficiency.com You can see my php info at this address: http://mindfulefficiency.com/test.php

I have tried almost every RewriteEngine script I have found to no avail. Please provide me with a script (which resides in the .htaccess file) that will remove the extensions from all of the files in my root directory.

Thanks very much.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5811



« Reply #3 on: March 12, 2011, 05:50:57 PM »

Well, first you would change all your internal links to drop the ".php", e.g., <a href="/contact">Contact</a> instead of /contact.php (the file itself keeps its current name). Then you need to do something in .htaccess to invisibly map /contact to /contact.php.

The simplest way is simply to stick a ".php" extension on the end of anything that isn't already a valid directory or file, and doesn't already end with ".php". The following may work for you:
Code:
RewriteEngine On
RewriteCond %{REQUEST_URI}  !-d
RewriteCond %{REQUEST_URI}  !-f
RewriteCond %{REQUEST_URI}  !\.php$
RewriteRule  ^(.*)$  /$1.php  [L]

In the future, if you rename your files to something else (such as .aspx), you would change ".php" to ".aspx" in the .htaccess file.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
mindf1
Newbie
*
Offline Offline

Posts: 4


« Reply #4 on: March 12, 2011, 09:35:45 PM »

Thanks for your response.

Cool, that worked but for some reason the CSS doesn't work anymore.

What shall I do?

Thanks in advance.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5811



« Reply #5 on: March 13, 2011, 05:01:50 AM »

You would have to also exclude .css files. Try this:
Code:
RewriteEngine On
RewriteCond %{REQUEST_URI}  !-d
RewriteCond %{REQUEST_URI}  !-f
RewriteCond %{REQUEST_URI}  !\.php$
RewriteCond %{REQUEST_URI}  !\.css$
RewriteRule  ^(.*)$  /$1.php  [L]

If you have other files, such as .js, you need to add them to the list.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
mindf1
Newbie
*
Offline Offline

Posts: 4


« Reply #6 on: March 13, 2011, 07:32:59 AM »

Great, thanks allot for the code. It worked very well.  Applause

I even had to exclude image files for those of you want to do this. (.png and .jpg files)

Have a nice day MrPhil!
Logged
morean51
Space Explorer
***
Offline Offline

Posts: 6



« Reply #7 on: March 15, 2011, 01:12:38 AM »

thank you for the code which is so handy to me
Logged
wilmatan
Intergalactic Cowboy
*****
Offline Offline

Posts: 52



« Reply #8 on: May 03, 2011, 06:39:54 AM »

Never knew I could hide the .php...Thanks for the info...Smile  Very Happy Very Happy Very Happy
Logged
avni111
Newbie
*
Offline Offline

Posts: 1


« Reply #9 on: January 21, 2013, 05:55:29 AM »

@MrPhil - Please help me too..  Help

I am using Linux Apache hosting (shared) of the other hosting company and all my files displays .PHP in url, I want to show them as .HTML

i tried many Rewrite codes inside my .htaccess file but they are not working. Sad

Presently my  website URLs are in below patern, i want all of them to be .HTML in address bar.

http://www.mywebsite.com/about_us.php
http://www.mywebsite.com/contact_us.php
http://www.mywebsite.com/product_details.php?prod_id=385

PLEASE HELP..THANKS IN ADVANCE. Friend
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5811



« Reply #10 on: January 21, 2013, 07:36:07 AM »

"other hosting company"? We can only support Lunarpages-hosted customers here. Sorry.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
Malin Cenusa
Customer Service Representative
Support
Spaceship Navigator
*****
Offline Offline

Posts: 84


The World Is Not Enough


WWW
« Reply #11 on: February 05, 2013, 01:25:20 AM »

@avni111 you should always inquire with your hosting provider about such matters as there are different server configurations and obviously even if this is an open forum it would be hard for us to assist.

However if you would want to move to us so that we can provide full assistance you can always review our plans here: http://www.lpwebhosting.com/hosting/web
Logged

Malin Cenusa

Customer Service Representative 2 - Managed Shared Hosting Team
Lunarpages Internet Solutions

Managed Hosting Now Available
http://www.lpwebhosting.com/managed

Website: http://lunarpages.com
Email: support@lunarpages.com
Phone: 1-714-521-8150
Community - http://www.lunarforums.com
Tutorials - http://www.lunarpages.com/tutorials/
Pages: [1]   Go Up
  Print  
 
Jump to: