【问题标题】:How to redirect htaccess to specific URL如何将 htaccess 重定向到特定的 URL
【发布时间】:2017-10-06 19:51:32
【问题描述】:

我有一个主页在site.pt/pt/home 的网站,所以我需要输入.htaccess,但我不知道如何...

我有这个代码:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

我该怎么做?

谢谢。

【问题讨论】:

  • 这是你的主站点/pt/home 到什么地方?
  • 我的主页是 site.pt/pt/home @MohammedElhag
  • 我知道了,你打算重定向到哪里?你说的是特定的网址,它在哪里?
  • 当我访问站点时,它会转到 site.pt,我需要将其转到 site.pt/pt/home @MohammedElhag
  • 有几种解决方案,所以您应该尝试提供更多详细信息,您是否想在此处重定向相同的页面?还是只想将家重定向到家? pt 目录是否存在?等等...

标签: .htaccess cpanel url-redirection


【解决方案1】:

试着把它放在RewriteEngine On之后:

RewriteCond %{REQUEST_URI} !^/pt/home [NC]
RewriteCond %{REQUEST_URI} !^/pt/home/.* [NC]
RewriteRule ^(.*)$ /pt/home/$1 [R=301,L]

这两个条件用于跳过已经以/pt/home 开头的请求,并且规则将所有其他请求重定向到那里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 2012-06-01
    相关资源
    最近更新 更多