.htaccess 重定向后隐藏子目录 url [英] .htaccess hide subdirectory url after redirect
问题描述
我正在将网站重定向到我创建的子目录.子目录包含 WordPress 的安装,现在我想从网站屏蔽子目录 url.
I'm redirecting a website to a subdirectory I created. The subdirectory contains an installation of WordPress and now I want to mask the subdirectory url from the website.
现在类似于 http://mywebsite.com/apt/
我想从 URL 中删除/apt/.
I want to remove the /apt/ from the URL.
我今天尝试了所有方法,在 Google 上搜索,尝试在我在这里找到的 htaccess 上写各种东西,但没有任何效果.
I tried everything today, searched on Google, tried to write various things on the htaccess I found here but nothing works.
在站点主目录的htaccess上,我用这段代码重定向
On the htaccess on the main directory of the site, I use this code to redirect
RewriteCond %{HTTP_HOST} ^mywebsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$
RewriteRule ^/?$ "http://www.mywebsite.com/apt" [R=301,L]
在我拥有的/apt/文件夹中的那个
And on the one in the /apt/ folder I have
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /apt/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /apt/index.php [L]
</IfModule>
# END WordPress
有人可以建议我如何隐藏 URL 中的/apt/扩展名吗?非常感谢.
Could someone suggest me how can I hide the /apt/ extension from the URL? Thanks a lot.
推荐答案
试试这个:删除重定向部分然后使用这个 insead:
Try with this: remove the redirect part then use this insead:
RewriteCond %{THE_REQUEST} ^GET /apt/
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^apt/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule !^apt/ apt%{REQUEST_URI} [L]
然后对主网站使用相同的代码.
then use the same code for the main website.
这篇关于.htaccess 重定向后隐藏子目录 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!