Jump to content

mydomain.com/site as a variable?


Mutley

Recommended Posts

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?
Link to comment
Share on other sites

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):
[code]RewriteRule ^([A-Za-z]+)$ gallery.php?page=$1[/code]
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.
Link to comment
Share on other sites

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

So your htaccess file should like this:
[code]RewriteEngine On

RewriteRule ^([A-Za-z]+)$ gallery.php?id=$1
RewriteRule ^([A-Za-z]+)/{[0-9+])$ gallery.php?id=$1&sub=$2 [L][/code]
Link to comment
Share on other sites

  • 3 weeks later...
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?
Link to comment
Share on other sites

  • 1 month later...
[quote author=shawn2page link=topic=109959.msg454799#msg454799 date=1161326102]
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?
[/quote]

Seconded.  How would I change the expression to allow number as well (in any order)
Link to comment
Share on other sites

  • 2 weeks later...
[quote author=wildteen88 link=topic=109959.msg444681#msg444681 date=1159710312]
I did a typo, I typed { instead of (. So use this as the last rewrite rule:
[code]RewriteRule ^([A-Za-z]+)/([0-9+])$ gallery.php?id=$1&sub=$2 [L][/code]
[/quote]

How would you do it with underscores? Such as:

mysite.com/this_is_my_page
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.