Reputation: 13644
I have a static website with files like index.php, blog.php, contact.php etc
How can I get my website addresses to work so that www.site.com/blog takes you to blog.php?
I think htaccess could do this for me, but am a php noob!
The only alternative I currently use is to create individual folders called 'blog, contact etc' which contains another index.php file inside it
thanks
Upvotes: 3
Views: 9860
Reputation: 139
In your .htaccess file on your server add
Options +MultiViews
Upvotes: 0
Reputation: 944020
I have a static website with files like index.php, blog.php, contact.php etc
If you are generating your documents with PHP, then the site is dynamic, not static.
How can I get my website addresses to work so that www.site.com/blog takes you to blog.php?
Assuming you are using Apache, turn on MultiViews
Upvotes: 0
Reputation: 58992
Yes, you can use mod_rewrite to rewrite all urls. The following will rewrite all non-existing files and folders to requested filename .php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
Visiting /blog
and it's not an existing directory will cause this rule to rewrite it as /blog.php
.
Upvotes: 11
Reputation: 15570
Have a read on mod_rewrite: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
Upvotes: 0
Reputation: 11421
Something like this should do it.
RewriteEngine on
RewriteRule ^(.*)$ $1.php [NC]
Upvotes: 0