2017. szeptember 19., kedd

Difference between URL masking and URL redirect

Hi guys. It's been a while since I wrote something on here. While I was looking at the URL redirects on my website, I noticed that I should actually mask the URLs that should look nicer. I have got a few redirects in order to use them on external referral sites and they end up hitting my website. When the resulting link is masked, it looks nicer and reveals less information to the visitor.

So the redirects I have got set up are as follows:

www.miklos.info/munka → www.miklos.info/hu/3/it-konzultacio?lang=hu
www.miklos.info/consulting → www.miklos.info/en/3/itconsultation?lang=en

When the above referring links are getting visited, they used to be rewritten in the browser title bar so the resulting links were displayed until now. I wanted the URL to be masked and the visited link URLs are not be rewritten but keep the original links in the browser title bar displayed, the content however would be served. I am using Apache as a web server on my website, so the Redirect and Rewrite rules can be used via the Rewrite Engine feature :-) . So far I had redirects in my webpage .htaccess file in the web root directory as below.

Redirect /munka /hu/3/it-konzultacio?lang=hu
Redirect /consulting /en/3/itconsultation?lang=en

The above redirects work fine but it results the browser's title bar containing the long, unmasked link when you used to visit the site. 


Note that here I do not need to redirect the request to another site, I just need them remain on the same site, but with different URLs. I would like the URL masked in the title bar. After having read the official documentation and pondering a little bit, I realized how can I mask the URLs. You can just simply use the RewriteRule directive! So simple. It masks the URLs and the serves the content from the resulting links without changing the URL in the display bar. Let's see how to solve the problem by using the correct rewrite rules. My configuration is as below. 

RewriteEngine On
RewriteRule ^munka$ /hu/3/it-konzultacio?lang=hu [L]
RewriteRule ^consulting$ /en/3/itconsultation?lang=en [L]

Save and quit the config file and reload the webpage in browser. After applying the new rewrite rules in Apache, I get the new content served but with the original URL! So with the word munka, the content on the line following is being served (/hu/3/it-konzultacio?lang=hu) and visiting the site with the word consulting in the URL in the end, the content is served which is on the line to the right after the word (/en/3/itconsultation?lang=en).


Voila! The web page(s) are served with the new, redirected content but the URL remains the original, masked! This is how you mask the URL in the title bar with Apache using the rewrite rule feature. 

😄

qmi
19 September, 2017



Nincsenek megjegyzések: