redirect

a!!!!1

Banned
Apr 20, 2008
508
7
0
I have a single link that I'd like to send people to. They'll be coming to it from various pages but rather than having a generic "domain.com/link" I want to be able to make the link look relevant to the page they're coming from, for example if they're coming from the "apples" page the link appears as "domain.com/apples/link" and if they're coming from the "oranges" page it appears as "domain.com/oranges/link" (or it could be link/apples and link/oranges, whatever). There are hundreds if not thousands of pages that will be linking to the same file so I don't want to have to make that many copies of it and upload all of them, I want to just make one and somehow have all the different links send the user to the same file. Is there any way to do that?
 


Not sure if this is what you're looking for exactly but this will redirect anything and everything to the "yourpage.php" page. So domain.com/wickedfirelovesboobs will redirect to yourpage.php and so on. Don't ask me to explain it cause I can't - found it in my htaccess goodies folder =p

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ yourpage.php [L]
 
Actually I know how to explain it. You know how people post links to wiickedfire.com/asfsadfs and no matter what you put it links to the same page (the dick roll)? I need something where I can link to domain/link/asdfsadf and no matter what the "asdfasfd" is, it sends you to the same page. But only if the "link" folder is specified, I don't want every single thing on the domain to redirect. You know what I mean?
 
Drop it in a directory.

domain.com/link/

Make a meta refresh link.html

Send your users through domain.com/link/oranges potatoes or whatever
 
Make a new directory for your "link". Let's call it link.

Now you have domain.com/link

In there put the "file" whatever that is, a page on your site, something they downlod, an affiliate link...if it's a link do a meta refresh and call it link.html for example.

Make a .htaccess with the following and put it in the directory /link:

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ [B]YOURPAGE.php[/B] [L]
Now any time you go to domain.com/link/ANYTHING it will redirect to /link/YOURPAGE.php
 
Make a new directory for your "link". Let's call it link.

Now you have domain.com/link

In there put the "file" whatever that is, a page on your site, something they downlod, an affiliate link...if it's a link do a meta refresh and call it link.html for example.

Alright I did that.

Make a .htaccess with the following and put it in the directory /link:

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ [B]YOURPAGE.php[/B] [L]
Now any time you go to domain.com/link/ANYTHING it will redirect to /link/YOURPAGE.php
How do you make a .htaccess?
 
I made a "download" directory with two files in it, #1 this html file "download.html":

Code:
<html>
<head>
<meta http-equiv="refresh" content="0;url=http://myafflink.whatever">
</head>

<body></body>

</html>
and #2 .htaccess:

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ [B]download.html[/B] [L]
so the goal is when you go to /download/anything it takes you to myafflink.whatever. But instead it says "nothing found for download anything" and doesn't do anything.
 
It does work because I tested it - check with your host why the htaccess isn't working could be some server settings.
 
Try This!

maybe mod_rewrite is disabled?

Create a PHP file like the following and execute it in your browser. It'll tell you if you have mod_rewrite enabled.

Code:
<html>
<head>
<title>Mod Rewrite Tester</title>
</head>

<body>
<?php
if (in_array("mod_rewrite", apache_get_modules())) {
   echo "It's enabled";
 } else {
    echo "It's not enabled man!!";
}
?>
</body>
</html>
 
maybe mod_rewrite is disabled?

Create a PHP file like the following and execute it in your browser. It'll tell you if you have mod_rewrite enabled.

Code:
<html>
<head>
<title>Mod Rewrite Tester</title>
</head>

<body>
<?php
if (in_array("mod_rewrite", apache_get_modules())) {
   echo "It's enabled";
 } else {
    echo "It's not enabled man!!";
}
?>
</body>
</html>

Copied and pasted that, uploaded it to same server, ran it and got:

Fatal error: Call to undefined function: apache_get_modules() in /homepages/22/d204831662/htdocs/tv/modtest.php on line 8
 
Are you sure you're running apache?

If so:
1. create a new file called .htaccess
2. put this in it:

Code:
[FONT=monospace]
[/FONT]Options +FollowSymLinks[FONT=monospace]
[/FONT]RewriteEngine on[FONT=monospace]
[/FONT]RewriteBase /[FONT=Verdana][/FONT]

3. upload to a new directory
4. go to that directory in your web browser
5a. if you see an error like 500. Your server doesn't have mod_rewrite
5b. if you see a directory listing then you do have it.
 
Another way to check is to use this:

Another way to check is to use this:

Create a .htaccess file with the following contents.

Code:
RewriteEngine On
RewriteRule ^link([^/]*)\.html$ rewrite2.php?link=$1 [L]
Then create a file named rewrite2.php and insert the following code into it.

Code:
<?php
 
 if($_GET['link']==1)
 {
         echo "You are not using mod_rewrite";
 }
 elseif($_GET['link']==2)
 {
         echo "You are using Apache mod_rewrite";
 }
 else
 {
         echo "Linux Apache mod_rewrite test";
 }
 
 echo '<p><a href="rewrite2.php?link=1">LINK1</a> = rewrite2.php?link=1</p>
                 <p><a href="link2.html">LINK2</a> = link2.html</p>';
 
 ?>
 
Too hard for understanding ((( I am reading this forum and try to learn HTML and nothing ((( Just nothing (((
 
For a slightly different (less SEO friendly) approach, you could make a custom 404 page and put the meta refresh in that. If you have something like cPanel, look for an option like "edit custom error pages" and you can edit it directly in the browser. Otherwise, the file is usually called 404.shtml and would be in a folder above your webroot.

But like I said, you should only use it if you don't care about SEO and throwing lots of 404s
 
Another way to check is to use this:

Create a .htaccess file with the following contents.

Code:
RewriteEngine On
RewriteRule ^link([^/]*)\.html$ rewrite2.php?link=$1 [L]
Then create a file named rewrite2.php and insert the following code into it.

Code:
<?php
 
 if($_GET['link']==1)
 {
         echo "You are not using mod_rewrite";
 }
 elseif($_GET['link']==2)
 {
         echo "You are using Apache mod_rewrite";
 }
 else
 {
         echo "Linux Apache mod_rewrite test";
 }
 
 echo '<p><a href="rewrite2.php?link=1">LINK1</a> = rewrite2.php?link=1</p>
                 <p><a href="link2.html">LINK2</a> = link2.html</p>';
 
 ?>

Tried that as well as your other post and got an error, so I'm assuming that means I just can't do it on this server?
 
Did you check with your host?

Nah I just went ahead and tested everything you both said and none of it worked so I just assumed I couldn't do it on this server. I'm running it on a shared host, I have a VPS and a dedicated server that I could switch it to to test but didn't know if it would be worth it (would it make a difference?).