...

View Full Version : htaccess redirect



jchrisphonte
01-30-2012, 04:24 PM
Hello All,

I have a dynamic url that i would like to redirect to a details page... I'm new to .htaccess files

here is what i have so far:

link that has to forward to www.hedgevent.com/details/eventdetails.php :


<a href="http://www.hedgevent.com/details/'.$urlevent.'.php?id='.$id.'" class="event">
here is an example linked url: http://www.hedgevent.com/details/Cocktails_On_The_Sound.php?id=100


what kind of scripting do i need to include in the htaccess file and on the receiving page (eventdetails.php) so that they connect??

Thank you in advance for your help.

Fou-Lu
01-30-2012, 05:20 PM
Wut? PHP hasn't a thing to do with .htaccess, the only thing that you *may* want to do is determine if mod_rewrite is in use and rewrite the links if you desire.
The receive page doesn't change. Mod rewrite links a url to a querystring, so the standard GET still applies to the script in use.
If you want to redesign the links, the very first step is adding an environment variable within .htaccess to declare that rewrite engine is on. Once that's complete, you can fetch that out of PHP and design your urls to match. For example:


if (isset($_SERVER['HASREWRITE'])) // Your environment variable
{
printf('Link: http://yoursite.com/article/%d', $articleid);
}
else
{
printf('Link: http://yoursite.com/article.php?articleid=%d', $articleid);
}

There is no automagic way to rewrite these, although use of an output buffer and replace may make it a lot easier so you don't have to manually write code like this. Becomes interesting though as you need a solid set of rules to work with.

jchrisphonte
01-30-2012, 05:28 PM
thanks for clarifying Fou lu... I 've been stumped with this for 4 days now and maybe i should explain it simpler instead of assuming all the information I received in the past was accurate.

I am trying to get links on this page under upcoming events: www.hedgegevent.com to go to a details page when clicked.

Is it possible to make one details page and have all the links go here with unique information for each event??

please do let me know if i was wrong to think this was an htaccess type of query??

Fou-Lu
01-30-2012, 08:16 PM
thanks for clarifying Fou lu... I 've been stumped with this for 4 days now and maybe i should explain it simpler instead of assuming all the information I received in the past was accurate.

I am trying to get links on this page under upcoming events: www.hedgegevent.com to go to a details page when clicked.

Is it possible to make one details page and have all the links go here with unique information for each event??

please do let me know if i was wrong to think this was an htaccess type of query??

Without following links since I'm at work, the answer is yes. That's PHP's job, to take input from the user in the form of either a querystring in get, or through other means like cookies, post and put, and use that data to dynamically generate what the content will be.
From development world, you completely ignore the use of mod rewrite. This is an added feature to convert a querystring into a slightly more readable approach. If you centralize a location to perform all the link building, then you can easily provide the data required, and write the rules to change between a querystring and a seo style link with minimal effort.

jchrisphonte
01-30-2012, 08:55 PM
i guess my question is -- if all the urls are different:

examples.
www.hedgevent.com/details/Cocktails_On_The_Sound.php?id=100
www.hedgevent.com/details/Distressed_Investing_Summit.php?id=124

how do i get these links to end up at the same place?? or to make sure I understand you, do I need to?

jmj001
01-31-2012, 10:23 AM
you just change them to all point at the one page my_display.php (or something like that) and use the id=xxx as the identifier on the display page

so the 2 example links would be
http://www.hedgevent.com/details/my_display.php?id=100
http://www.hedgevent.com/details/my_display.php?id=124

the id's 100 + 124 will be what you use to get the detail for the specific event out of the db and display it

jchrisphonte
01-31-2012, 01:38 PM
great!!! I understand now...

one last question and I will be forever in your debt, how could i rewrite the above example urls to include the event name yet still point to the file?? A big component of this site would be the SEO friendly url for the event names coming up in search engines... would I have to include the event name after the "?" as well?

jmj001
01-31-2012, 03:34 PM
there's not really any need because on the receiving page you can extract it from the database along with your query for the other detail...

however...

if you really really want to you can simply make the link to be:
http://www.hedgevent.com/details/my_display.php?id=100&name=Cocktails_On_The_Sound

jchrisphonte
01-31-2012, 03:54 PM
ok thanks jmj. I appreciate your help.

http://www.hedgevent.com/eventdetails.php/Cocktails_On_The_Sound?id=100
hedgevent.com/details/my_display.php?id=100&name=Cocktails_On_The_Sound

which one of the above would a search engine be able to pick up??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum