Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
URL redirection using htaccess?
Old 05-08-2009, 10:14 AM URL redirection using htaccess?
Super Talker

Posts: 101
Trades: 0
Suppose you have many links leading to a site like:

thelongestdomainnameintheworldever.com

so instead of typing this on all your <a href>'s you type something like hi.com. Can you tell your htaccess file that every time hi.com appears on your website that it should actually link to:

thelongestdomainnameintheworldever.com

What would be the actual htacess code for this?
Towhid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-19-2009, 04:25 PM Re: URL redirection using htaccess?
Average Talker

Posts: 18
Trades: 0
Assuming that you have access to hi.com to change the htaccess file there, you need to do a 301 redirect. How exactly you do it depends on a lot of things, like do both domains point to the same site? Are you just redirecting one page or all pages? Does hi.com/foo.html get redirected to reallylongurl.com/foo.html or something else?

There's tons of tutorials on 301 redirects out there, this one looks decent:
http://www.isitebuild.com/301-redirect.htm
__________________
30 Day Money-Back Guarantee -
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

awatson is offline
Reply With Quote
View Public Profile
 
Old 05-19-2009, 05:18 PM Re: URL redirection using htaccess?
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
I think you are misunderstanding the purpose of .htaccess, but I cannot be sure without a more concrete explaination of what you are trying to do. If you are just trying to shorten your URLs I don't recommend using redirects for this. You could accomplish this with a simple rewrite rule, but having all of your internal links converted to external links which get redirected to an internal page seems like a bad approach to me.

If your domain name is seriously too long to type out in your code, you can do something like this:
PHP Code:
<a href="<?php $_SERVER['HTTP_HOST']; ?>/index.php">My Link</a>
or

PHP Code:
<?php
$url 
$_SERVER['HTTP_HOST'];
?>
<a href="<?php echo $url?>/index.php">My Link</a>
Not an ideal situation, but I really advise against using another domain and redirection.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 05-19-2009 at 05:24 PM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-21-2009, 03:33 PM Re: URL redirection using htaccess?
Skilled Talker

Posts: 87
Trades: 0
Or... why are you using complete urls at all??? If you need to use absolute file pathing, then simply do

/directory/file.file

This will go to http://www.thelongestdomainnamever.c...tory/file.file
__________________

Please login or register to view this content. Registration is FREE
- The most comprehensive online resource for students and educators.
yuechen is offline
Reply With Quote
View Public Profile Visit yuechen's homepage!
 
Old 05-25-2009, 10:31 PM Re: URL redirection using htaccess?
Junior Talker

Posts: 3
Trades: 0
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.short-example.com$ [NC]
RewriteRule ^(.*)$ http://www.long-example.com/$1 [L,R=301]
marxfinder is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to URL redirection using htaccess?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31912 seconds with 12 queries