3

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

5
  • 1
    Have you at least read some htaccess tutorial? If yes, what did you not understand more precisely? Commented Jun 7, 2011 at 15:31
  • 1
    possible duplicate of rewrite url using htaccess file ? Commented Jun 7, 2011 at 15:32
  • I don't understand the vanity around URL's, personally... Using folders is a good practice to organize code. Commented Jun 7, 2011 at 15:33
  • Well, that guys thinks php pages are "static" web pages ... that says enogh. Commented Jun 7, 2011 at 16:44
  • @marvinlabs - took a look, couldn't find what i was looking for. @fosco - I want people to be able to enter www.mydomain.com/support rather than www.mydomain.com/support.php - that was the only reason for this one @Angel O'Sphere the website is static with no backend database, php pages can of course be static if you don't add dynamic content to them! Commented Jul 12, 2011 at 8:22

5 Answers 5

11

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@Konerak Well, he did mention .htaccess so i think it's fair to assume he is using Apache.
Just to make it clear: Thats the content of the .htaccess file
0

Something like this should do it.

RewriteEngine on
RewriteRule ^(.*)$ $1.php [NC]

Comments

0

Have a read on mod_rewrite: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Comments

0

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

2 Comments

Just if the extension is php does not make it a dynamic page. You can have a static page named index.php. :)
Yeah but from the context of his question one would assume it is not a static page, but now as I think about your comment, that guy perhaps has indeed pure html in his php and the server configured to return content type text/html, lol ...
0

In your .htaccess file on your server add

Options +MultiViews

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.