htaccess rewrite rule

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rajsekar2u
Forum Commoner
Posts: 71
Joined: Thu Nov 20, 2008 4:23 am

htaccess rewrite rule

Post by rajsekar2u »

HI,

This is the first time am using htaccess. I didn't have much knowledge in this. Please help me.

I need a rewrite rule which have to hide everything other than the site's base URL.

Eg. If the site URL is "http://example.com/index.php?id=1"

then it should show only "http://example.com/"

I've tried somethings but i didn't got the result.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: htaccess rewrite rule

Post by requinix »

You can't hide the URL like that.
rajsekar2u
Forum Commoner
Posts: 71
Joined: Thu Nov 20, 2008 4:23 am

Re: htaccess rewrite rule

Post by rajsekar2u »

Hi,

Thanks for your reply.

Then is it possible to show as a folder
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: htaccess rewrite rule

Post by cpetercarter »

I think that what tasairis means is that you cannot use .htaccess to change what appears in the address bar of the browser. You can however use it to "divert" a request for one url (eg "mysite.com/podcasts") to a different url ("mysitecom/index.php?page=podcasts").

If you want to change the address as it appears in the address bar, you need to look at Javascript.
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: htaccess rewrite rule

Post by manRay »

You can change what is in the address bar by not including the file extension.
ex) <a href="home"></a> It will look something like www.yourwebsite/home in the address bar
This will bring you to a file called home in the current directory, I am not too sure how it work when there are other files with the same name but different extensions.

Hope this helps.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: htaccess rewrite rule

Post by cpetercarter »

I don't think this is quite right. http://www.mysite.com/home points to the directory "home". If the "home" directory exists, the server will look for a file "index.html" in the home directory, or - failing that, and depending on configuration settings - it will look for "index.php". If there is no index file, the server will return a "not found" error, or will display a list of the contents of the "home" directory, again depending on config settings. If the "home" directory does not exist, the server returns a "not found" error.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: htaccess rewrite rule

Post by requinix »

If you're using Apache and have the MultiViews option enabled, Apache will look for files with known extensions after checking for matching directories. Thus "/home" could refer to the /home directory or the /home.* file.

It doesn't count just any extension - it has to know about it first, like through an AddHandler or AddType directive.
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: htaccess rewrite rule

Post by manRay »

while on the topic, what do I change in order to be able to use index.php (instead of index.html, ie: http://www.mysite.com) as my home page?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: htaccess rewrite rule

Post by requinix »

manRay wrote:while on the topic, what do I change in order to be able to use index.php (instead of index.html, ie: http://www.mysite.com) as my home page?
DirectoryIndex in your .htaccess. Most preferred filenames left, least preferred right.

Code: Select all

DirectoryIndex index.php index.html
Post Reply