Jump to content


Photo

mydomain.com/site as a variable?


  • Please log in to reply
17 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 29 September 2006 - 01:06 PM

I've done a nice bit of code for a gallery, each gallery section is divided like this:

gallery.php?id=1
gallery.php?id=2
gallery.php?id=3

etc.

Can I make it so if you put in www.mydomain.com/site1
... it goes to gallery.php?id=2 and again for .com/site2 goes to gallery.php?id=2 etc.

Is this possible, if so how?
~ Mutley.

#2 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 29 September 2006 - 01:13 PM

yes it is. If you want to do it exactly as you have there you would do it by using mod_rewite. First you have to make sure that you have access to the .htaccess file on your server

#3 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 29 September 2006 - 01:14 PM

Any examples? I have htaccess, not sure how to use it though.
~ Mutley.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 September 2006 - 02:58 PM

Add the following to your htaccess file:
RewriteEngine On

RewriteRule ^site([0-9]+)$ gallery.php?id=$1

If you type in site1 it'll called gallery.php with the url parameter id=1
if site99 then it'll call gallery.php with the url parameter id=99

#5 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 29 September 2006 - 03:38 PM

Thanks, so if I wanted sections called "outside" and "hobbies" instead of "site1" and "site 2", what would I put?

Is there a way so when you add new sections you don't have to keep editing the htaccess?
~ Mutley.

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 September 2006 - 03:58 PM

Rather than send a numerical id to gallery.php you'll want to send a string instead. So you might want to do something like this, if you want to use outside, hobbies rather than site1, site2 or sitex (x being a number):
RewriteRule ^([A-Za-z]+)$ gallery.php?page=$1
This time when you do something like this:
mysite.com/outside it'll call gallery.php with the url parameter id=outside

Also with that you dont have to keep editing the htaccess file. However you may need to chnage the code in gallery.php though now that you are sending a string rather than a number in the id variable.


#7 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 29 September 2006 - 04:06 PM

Can I put .htaccess in a subdirectory? If my site is there? Or does it have to be in root folder?
~ Mutley.

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 September 2006 - 05:08 PM

htaccess folder can be placed anywhere. So you can place it in the subdirecotry if you want. However keep in mind what ever setting/configuration you have in the htaccess file will work when you go to the subfolder you put the htaccess file in.

#9 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 29 September 2006 - 05:46 PM

Thanks, another question.

So now I have this:
mysite.com/section

What if I have another subdirectory? so ?id=1&sub=3 or whatever, can I do this:
mysite.com/section/sub

Thanks alot Wild teen, very helpful. :)
~ Mutley.

#10 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 September 2006 - 12:09 PM

Yeah. You just need to add a newr rewrite rule after your other one for that:
RewriteRule ^([A-Za-z]+)/{[0-9+])$ gallery.php?id=$1&sub=$2

So your htaccess file should like this:
RewriteEngine On

RewriteRule ^([A-Za-z]+)$ gallery.php?id=$1
RewriteRule ^([A-Za-z]+)/{[0-9+])$ gallery.php?id=$1&sub=$2 [L]


#11 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 30 September 2006 - 09:23 PM

It's not seeming to work the last part.

If I do:
mysite.com/test
...it works fine, however if I do:
mysite.com/test/1
...it does a 404 Not found?


~ Mutley.

#12 oldmanice

oldmanice
  • Members
  • PipPipPip
  • Advanced Member
  • 134 posts
  • LocationIn Your Garden At Night

Posted 01 October 2006 - 12:07 AM

Try mysite.com/test1
Join my Froums www.phpbbplanet.com/darkwinter

#13 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 01 October 2006 - 09:29 AM

Nope, that doesn't work, it just thinks it's called "nick1".
~ Mutley.

#14 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 October 2006 - 01:45 PM

I did a typo, I typed { instead of (. So use this as the last rewrite rule:
RewriteRule ^([A-Za-z]+)/([0-9+])$ gallery.php?id=$1&sub=$2 [L]


#15 shawn2page

shawn2page
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 October 2006 - 06:35 AM

This code has been helpful for me but I am having a problem.  I have set the code up as follows:

RewriteRule ^([A-Za-z]+)$ profile.php?ID=$1

So is they type www.mysite.com/johndoe it will take them to johndoe's page on our site.  But the problem I have is if a member signs up with member name mark2000 the code will not work.  How can i set it up to work with numbers?

#16 FuzzyLogik

FuzzyLogik
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 December 2006 - 06:44 AM

This code has been helpful for me but I am having a problem.  I have set the code up as follows:

RewriteRule ^([A-Za-z]+)$ profile.php?ID=$1

So is they type www.mysite.com/johndoe it will take them to johndoe's page on our site.  But the problem I have is if a member signs up with member name mark2000 the code will not work.  How can i set it up to work with numbers?


Seconded.  How would I change the expression to allow number as well (in any order)

#17 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 22 December 2006 - 08:17 PM

I did a typo, I typed { instead of (. So use this as the last rewrite rule:

RewriteRule ^([A-Za-z]+)/([0-9+])$ gallery.php?id=$1&sub=$2 [L]


How would you do it with underscores? Such as:

mysite.com/this_is_my_page
~ Mutley.

#18 Mad.Man

Mad.Man
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 22 December 2006 - 08:45 PM

RewriteRule ^([A-Za-z]+)/([0-9+])$ gallery.php?id=$1&sub=$2 [L] this_is_my_page
Mad aint the word




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users