vincent vincent - 4 months ago 19
Apache Configuration Question

About Apache Rewrite Function to Shorten URL

I have an URL "http://10.21.50.66:8123/test/file/index.htm" which hosted in Apache server. I would like to shorten the URL to just "http://10.21.50.66:8123/" and I managed to do it by using Rewrite function in httpd.conf. However, when I type "http://10.21.50.66:8123/" in browser, it will redirect and the URL of the browser will change back to the long url "http://10.21.50.66:8123/test/file/index.htm". What I would like to archive is that when every time I type "http://10.21.50.66:8123" in browser, the browser will open "http://10.21.50.66:8123/test/file/index.htm" but the URL on the browser will still showing "http://10.21.50.66:8123/". Below is the currecnt setting:

RewriteEngine On

RewriteRule ^/$ http://10.21.50.66:8123/test/file/index.htm [R,L]


Any ideas?

Thanks in advance.

Answer

If you use [R], the Apache will return response code 302 to the browser (with the new Location), which will cause that new URL to appear in address bar.

try:

RewriteEngine On
RewriteRule ^/$ /test/file/index.htm [L]
Comments