【问题标题】:htaccess hide subdirectory from url after redirecthtaccess 重定向后从 url 隐藏子目录
【发布时间】:2023-03-11 03:41:01
【问题描述】:

我在本地服务器上运行相同的应用程序 - 一个在“localhost”中,另一个在“localhost/bss/”中。我的域端口转发给他们。所以 www.domain.com:1111 和 sub.domain2.info:1111 指向 localhost。现在他们都显示本地主机。我需要将 sub.domain2.info:1111 (localhost) 重定向到 sub.domain2.com:1111/bss/ (localhost/bss) 但不想看到'/bss'

我在 localhost 中的 .htaccess 目前是这样的 -

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php/$1 [L]

Options -Indexes 

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)sub.domain2.info:1111$
RewriteRule (.*) /bss/$1 [R=301,L]

localhost/bss 中的 .htaccess 没什么特别的 -

RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php/$1 [L]

Options -Indexes

非常感谢您的回复。尝试了一些,但似乎没有任何效果!

【问题讨论】:

    标签: php .htaccess server url-redirection


    【解决方案1】:

    假设您使用 Apache Server 来实现这一点。如果您在本地环境中工作,您也可以尝试使用虚拟主机 你可以为你的子域试试这个

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^sub\.domain2\.com$
    RewriteCond %{REQUEST_URI} !^/bss
    RewriteRule ^(.*)$ /bss/$1 [L]
    

    通过查看您的评论添加此内容,您可以设置virtualhosts in linux

    顺便说一句,我不明白你为什么在域名中使用这些端口

    【讨论】:

    • 您好,感谢您的回复。它是一个转发的公共端口,所以我不必像 '.com:1111$' 一样输入 ':1111' 吗?问题是我尝试使用或不使用端口..在子目录(localhost/bss/)内的 .htaccess 中添加了该代码,但它仍然显示 sub.domain.com:1111/bss/ 并且虚拟主机编辑由于某种原因不起作用在我的centos服务器中。我正在使用 centos 中的 xampp。
    猜你喜欢
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    相关资源
    最近更新 更多