Jecki Jecki - 9 months ago 65
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 ^{REQUEST_URI} [L,NE]

example of the short url

it will be redirect to

then it will hit the actual url

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 Source

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 in the redirect, e.g. in PHP this would be as follows:

header("Location:$expanded_path", true, 301);

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