【问题标题】:php htaccess redirect url contains 'foldername'php htaccess 重定向 url 包含“文件夹名”
【发布时间】:2016-10-18 00:25:27
【问题描述】:

如果用户使用“http://example.com/site/”链接到“http://example.com”,我想重定向

我已经搜索并修改了许多示例的 htaccess,但它没有重定向。

我已尝试使用 rewritecond、重定向,但没有按照需要进行重定向。

RewriteCond %{HTTP_HOST} ^https\:\/\/example\.com\/site\/ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteCond %{REQUEST_URI} !^/site/
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteCond %{REQUEST_URI} !^/site/.*$
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteRule ^/site/(.*)$ https://example.com/$1 [L,R=301]

最后我保留了我的 htaccess,如下所示。

HTACCESS代码如下

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

我不知道克服此类问题的可能解决方案。 请帮助我。提前致谢。

【问题讨论】:

  • 如果您尝试在不中断文件夹的情况下重写 cond,您可能需要考虑使用 RewriteCond %{REQUEST_FILENAME} !-d

标签: php apache .htaccess redirect mod-rewrite


【解决方案1】:

改变需要时间

在修改 .htaccess 文件时,请注意更改可能需要一段时间才能观察到。该文件不是 php 或 html,而是一个服务器配置文件。我发现在 GoDaddy 等公共主机上,它最多需要 20 分钟。

将旧文件重定向到新文件路径:

# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html

来源:

http://www.htaccess-guide.com

https://mediatemple.net/community/products/grid/204643080/how-do-i-redirect-my-site-using-a-htaccess-file

【讨论】:

    猜你喜欢
    • 2013-10-08
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多