Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess rewrite without redirect

All i want to do is to rewrite url from www.exaple.hu to www.exaple.cz/hu. So under address www.exaple.cz/hu is displayed content from adress www.exaple.hu.

So when user type www.exaple.cz/hu, user is not redirected to www.exaple.hu but content from www.exaple.hu is displayed under domain www.exaple.cz/hu (so in adress bar is www.exaple.cz/hu).

like image 703
born2fr4g Avatar asked May 04 '12 16:05

born2fr4g


3 Answers

You will need to enable mod_proxy in your Apache config for that. Once mod_proxy is enabled, enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.exaple\.cz$ [NC]
RewriteRule ^(hu)/?$ http://www.exaple.$1 [L,P,NC]
like image 182
anubhava Avatar answered Nov 08 '22 02:11

anubhava


Are the files for www.exaple.cz/hu and www.exaple.hu on the same server?

If yes, I would create a symbolic link so that www.exaple.cz/hu content directory is pointing to www.exaple.hu content directory.

For example if server A has directores:

  • /var/www/html/A which includes files for: www.exaple.cz/hu
  • /var/www/html/B which includes files for: www.exaple.hu

cd /var/www/html/

ln -s /var/www/html/B A

this way, you only have one source but link ways to get to the source.

If the two URLs are pointing to two diff servers, you can try mounting the two and using the slink Or.. include "www.exaple.hu" as a frame in www.exaple.cz/hu?

like image 30
elle Avatar answered Nov 08 '22 03:11

elle


If the files are on the same server, you may delete the add-on domain in (cpanel) and re-add the domain but this time select the other domain's working directory.

If the link structure of your domain is like:

<a href="/path/page">Link</a>

You can use the new site now without any problems.

like image 40
Tarik Avatar answered Nov 08 '22 03:11

Tarik