.htaccess to mask url and redirect domain name to subdirectory

守給你的承諾、 提交于 2020-01-06 12:45:06

问题


Hi folks I'd appreciate some .htaccess advice.

I have two wordpress installations. "A" which is in my ISP's Linux server root directory and "B", which is in a subdirectory of the same server called "directoryB".

Actual structure is:= A.com A.com/directoryB/

I own two domain names A.com and B.com. I want people to use the address B.com when accessing everything on directoryB, not A.com/directoryB/.

I want to leave the "real" "A" alone - no redirections!

I have been assured this can be done using the .htaccess file, but I've failed so far! I have managed to "mask" the home page of "B" using cPanel, but it reverts back to A.com/directoryB/ once you move away from the home page. I'm also not sure if the .htaccess ought to be in the root or subdirectory.

All I want is to mask the A.com/directoryB/ with B.com/ every time it appears on the address bar......

Thanks in advance for any help!


回答1:


Put this in a .htaccess file in directoryB and see if it works:

RewriteCond %{HTTP_HOST} !^B.com$ [NC]
RewriteRule (.*) http://B.com/$1 [R=301,L]



回答2:


Put this in .htaccess in your root directory -

Options +FollowSymlinks

<IfModule mod_rewrite.c>
RewriteEngine on

Redirect permanent /directoryB http://B.com

</IfModule>



回答3:


The htaccess in public_html is:-

BEGIN WordPress


RewriteEngine On
Redirect permanent /directoryB http://B.com
RewriteRule ^test/([^/]*)/$ /test/login/?id=$1
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

END WordPress

Options -Indexes

=============== this is the htaccess from "directoryB"

BEGIN WordPress


RewriteEngine On
RewriteBase /directoryB/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /directoryB/index.php [L]

END WordPress

Options -Indexes



来源:https://stackoverflow.com/questions/6042828/htaccess-to-mask-url-and-redirect-domain-name-to-subdirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!