Setup like php.net/this?

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
FuzzyLogik
Forum Newbie
Posts: 18
Joined: Tue Dec 12, 2006 12:15 am

Setup like php.net/this?

Post by FuzzyLogik »

I would like to set up my page to be able to be used like this:

http://www.mysite.com/this

or

http://www.mysite.com/that

(without creating separate folders for each and making an index file )

I am using apache, so if I have to use .htaccess, I can.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Yes, you can do that with .htaccess file.

Code: Select all

DirectoryIndex index.php
FuzzyLogik
Forum Newbie
Posts: 18
Joined: Tue Dec 12, 2006 12:15 am

Post by FuzzyLogik »

dibyendrah wrote:Yes, you can do that with .htaccess file.

Code: Select all

DirectoryIndex index.php
Can I get a bit of an explanation? :)

I was going to use:

Code: Select all

RewriteRule ^([A-Za-z]+)$ page.php?page=$1
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

FuzzyLogik wrote:
dibyendrah wrote:Yes, you can do that with .htaccess file.

Code: Select all

DirectoryIndex index.php
Can I get a bit of an explanation? :)

I was going to use:

Code: Select all

RewriteRule ^([A-Za-z]+)$ page.php?page=$1
This change the default directory page into the given default page.
If you want to open mydefaultpage.php when you visit some url suppose :

http://xyz.com/pub/
and you want mydefaultpage.php to be opened rather than index.php. use

Code: Select all

DirectoryIndex mydefaultpage.php

And in your case,

Code: Select all

RewriteRule ^([A-Za-z]+)$ page.php?page=$1
RewriteRule is not needed for your current need. They are basically used for security reasons. It might be preventing from hotlinking etc...
FuzzyLogik
Forum Newbie
Posts: 18
Joined: Tue Dec 12, 2006 12:15 am

Post by FuzzyLogik »

I don't think you understand what I am trying to do :)

If you go to php.net/mail it goes to a different place than php.net/include

I want to do that with my site...

I figured it out, sorta:

RewriteRule ^([A-Za-z]+)/{[0-9+])$ index.php?word=$1


This works perfectly.

I say mysite.com/word and it goes to mysite.com/index.php?word=word

The problem is, I need multiple selectors for my static links (home/about/contact, etc)

so I tried:

RewriteRule ^home$ index.php?page=home


But the two of them don't play nice together.. the one on top trumps the one on bottom.

Anyone know how to fix this?

Thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

see http://www.php.net/docs.php
http://www.php.net/docs.php wrote:You can also get more information about php.net URL shortcuts by visiting our URL howto page.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

FuzzyLogik wrote:I don't think you understand what I am trying to do :)

If you go to php.net/mail it goes to a different place than php.net/include

I want to do that with my site...

I figured it out, sorta:

RewriteRule ^([A-Za-z]+)/{[0-9+])$ index.php?word=$1


This works perfectly.

I say mysite.com/word and it goes to mysite.com/index.php?word=word

The problem is, I need multiple selectors for my static links (home/about/contact, etc)

so I tried:

RewriteRule ^home$ index.php?page=home


But the two of them don't play nice together.. the one on top trumps the one on bottom.

Anyone know how to fix this?

Thanks.
Okay. I thought you are trying to load different default pages for folders.

In your URL
http://www.mysite.com/this

I thought "this" was folder rather than file. Sorry for misunderstanding.

So, are you trying to achive somehing like http://www.php.net/urlhowto.php ?
Post Reply