Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-12-2011, 05:30 PM   PM User | #1
RyanK
New Coder

 
Join Date: May 2011
Posts: 22
Thanks: 4
Thanked 0 Times in 0 Posts
RyanK is an unknown quantity at this point
Friendly static php urls

I have read many articles on making friendly URLs but I can't seem to get it working properly.

My site is hosted on a Linux box with Apache.

All I want to do is drop the file extensions so /hello.php shows as /hello

For the purposes of setting this up, I am working with a simple hello world file.

[code] <?php
Echo "Hello, World!";
?> [code]

First I saved the file as "hello.php". When I navigate to mysite.com/hello.php the page appears normally.

Next, I added the following to my .htaccess

Code:
<Files hello>
ForceType application/x-httpd-php
</Files>
My desire is to leave my files in their current format on the server, but simply drop the extension in the URL. I couldn't find a way to do such, so I renamed the file from "hello.php" to "hello". When I navigate to mysite.com/hello I get a prompt asking if I wish to open or save the file. If I choose to open it, I see a text document with the code the same as I would if I right-clicked and chose View Page Source.

I simply wish the file to open and display normally.

The .htaccess file is in the same directory as the php file.
RyanK is offline   Reply With Quote
Old 07-09-2011, 08:25 AM   PM User | #2
Cags
New Coder

 
Join Date: Jul 2011
Posts: 67
Thanks: 0
Thanked 13 Times in 13 Posts
Cags is an unknown quantity at this point
Personally I'd just use mod_rewrite to redirect all requests for extensionless paths that don't exists to .php...

Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_-]+)$ $1.php [L]
Cags is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:04 AM.


Advertisement
Log in to turn off these ads.