Forum Moderators: coopster

Message Too Old, No Replies

Can the user just navigate to a page without typing .php at the end

Address bar in the browser not to show .php

         

mvaz

8:53 am on Jul 8, 2008 (gmt 0)

10+ Year Member



Hello, I was wondering if there was a way using php to enable users to visit a particular page on my website by typing just ‘www.mysite.com/messageboard’ instead of ‘www.mysite.com/messageboard.php’ – basically they not having to type the .php.

Also, I was wondering if it was possible to show just that in the address bar of the browser.

Any help is greatly appreciated. Thank a lot to everyone who has thus far assisted me in with my queries.

dublinmike

12:41 pm on Jul 8, 2008 (gmt 0)

10+ Year Member



You can use a RewriteRule in your .htaccess file to accomplish this. For example, something like:


RewriteRule ^messageboard$ messageboard.php

You'll need other stuff at the top of your .htaccess file in order to get that to work, it may or may not already exist. If needs be, it should look something like this:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mysite.com
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

This just says to turn the URL rewriting engine on and then make sure that people don't access your site by going to mysite.com as opposed to www.mysite.com. Anyway, hope this helps.

g1smd

1:12 pm on Jul 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Which URL do you want to be indexed?

If you use a rewrite, beware that both URLs could end up getting indexed.

If you use a redirect, only one of them can be indexed.

.

If you just need this as a type-in, then use a redirect:

RewriteRule ^messageboard$ http://www.domain.com/messageboard.php? [R=301,L]

The trailing ? on the target URL kills any extraneous query string data that could cause a duplicate content issue.

I use this on one site. Members can simply type domain.com/member in their browser, and they are 301 redirected to www.domain.com/forum/login.php?somestuff=somevalue.

Heck. Look where bt.com/phonebook or bbc.co.uk/news takes you for example.