I have a static website with files like index.php, blog.php, contact.php etc开发者_Python百科
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
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
.
Something like this should do it.
RewriteEngine on
RewriteRule ^(.*)$ $1.php [NC]
Have a read on mod_rewrite: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
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
In your .htaccess file on your server add
Options +MultiViews
精彩评论