Mobile app version of vmapp.org
Login or Join
Si4351233

: Short and friendly URL for affiliate links This is my first question here on Pro Webmaster... I'm really glad to be here! I believe this question will have a simple answer but I'm starting

@Si4351233

Posted in: #Htaccess #Links #ModRewrite #Redirects

This is my first question here on Pro Webmaster... I'm really glad to be here!

I believe this question will have a simple answer but I'm starting with htaccess and I want to learn something about this file and its rules.

I have a long and ugly affiliate link but I want to create a 301 redirect to this URL, without typing it. My website is www.matthewlabs.com/ and I want to use a link like www.matthewlabs.com/wishonlist/appstore which automatically redirects to my affiliate link.

I tried to write this in my htaccess file:

Redirect 301 /wishonlist/appstore myAffiliateLinkHere

but it doesn't work. Must the directory /wishonlist/appstore exist to redirect? Because now I receive a 404 error...
And to use this link, can I create a simple link with html a tag?

<a href="http://www.matthewlabs.com/wishonlist/appstore">Click</a>


Thank you so much for your time and I hope you can help me!

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Si4351233

1 Comments

Sorted by latest first Latest Oldest Best

 

@Nimeshi995

Your .htaccess file needs to look something like this:


RewriteEngine on

RewriteRule [URL to redirect from] [URL to redirect to] [options]


RewriteEngine on basically switches the mod_rewrite module on.

Then you need to say what the URL you're expecting people to enter looks like, you can use regular expressions here, in fact, the whole thing IS a regular expression.

URL to redirect to is usually internal, but it should work with a full link.

So in practice, something like:


RewriteEngine on

RewriteRule ^/wishonlist/appstore(/)?$ myAffiliateLinkHere [301,L]


The ^ and $ to denote the start and end of the URL, and (/)? means that it can be entered with or without a trailing slash and still work.

Options - The 301 basically says send a 301 header, and L says this is a 'last instruction' - after which no more instructions should be processed.

There's a good wealth of options available, check the documentation - but here's a link to a good cheat sheet I always keep handy: www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme