Mobile app version of vmapp.org
Login or Join
Gonzalez347

: Creating redirects list from a domain alias to a primary domain I am trying to set up a list of redirects in my .htaccess to create a manually defined 'short url' list, whereby the short

@Gonzalez347

Posted in: #CustomShortUrl #Htaccess #Redirects

I am trying to set up a list of redirects in my .htaccess to create a manually defined 'short url' list, whereby the short url domain ("short.com") is set up as an alias for the destination domain ("longdomain.com").

The problem I'm running into is that –as expected– this basic redirect from the root works fine:

Redirect /howto longdomain.com/tutorials/how-to-do-something
Redirect /where longdomain.com/directions/where-is-my-car


...but is not suitable for redirecting to another domain. However, including the domain name like this:

Redirect short.com/howto longdomain.com/tutorials/how-to-do-something
Redirect short.com/where longdomain.com/directions/where-is-my-car


...is not working for the domain alias. It doesn't redirect, it just loads the content (/howto and /where) from the primary domain. Content that doesn't exist there I might add, so it ends up showing nothing.

Is there any way to create a similar redirects list from a domain alias to a primary domain? Or do I need to do a Rewrite for this? And what would that look like?

EDIT - A HOPEFULLY BETTER DESCRIPTION OF THE ISSUE
I have a short and a long domain, both with the same DNS, the short domain set up as an alias for the primary.
I need to create short urls to content on the primary domain. I will do this manually as I need readable URL's, not randomly generated strings. So: short.com/snowwhite would go to long.com/stories/fairytales/snowwhiteandthesevendwarfs.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Gonzalez347

2 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

The Redirect directive doesn't pay any attention to the current host name. Your intention of

Redirect short.com/howto longdomain.com/tutorials/how-to-do-something


appears to be to only redirect when the domain name is "short.com". mod_alias's redirect doesn't suport this syntax. The short.com/howto argument must only be a URI path (starting with a slash).

You could solve this problem using the <if> directive

<If "%{HTTP_HOST} == 'short.com'">
Redirect permanent /howto longdomain.com/tutorials/how-to-do-something
</If>


Alternately, you could use mod_rewrite:

RewriteEngine on
RewriteCond %{HTTP_HOST} short.com [NC]
RewriteRule ^/howto$ longdomain.com/tutorials/how-to-do-something [L,R=301]


I have made the redirects permanent (301) redirects in my above examples which is more SEO friendly than the default 302 temporary redirects you had been using.

10% popularity Vote Up Vote Down


 

@Hamaas447

Why not set up a CNAME record from short.com pointing to longdomain.com and then, based on your examples, the incoming requests would work without any short.com .htaccess rules.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme