Jecki Jecki - 23 days ago 9
Apache Configuration Question

short url and preview data

i'm using the following rule to produce short url ,

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule ^ http://maindomain.com/shortener%{REQUEST_URI} [L,NE]

example of the short url domain2.com/j3


it will be redirect to

http://maindomain.com/shortener/j3

then it will hit the actual url

http://maindomain.com/web/article/section/192392


now the issue is when i share the short url in the twitter its not give you the privew images or data ,

any advise here to adjust the rewrite rule or its the logic itself need to be adjusted

Answer

Try reducing it to one redirect:

RewriteCond %{HTTP_HOST} ^(?:www\.)?shortdomain\.com$ [NC]
RewriteRule ^(?!shortener/).+ shortener/$0 [NS,L]

Then your shortener code should do the lookup as normal but include maindomain.com in the redirect, e.g. in PHP this would be as follows:

header("Location: http://maindomain.com/$expanded_path", true, 301);

This assumes your short domain is just an alias for your main domain so they have the same codebase.