【问题标题】:.htaccess redirect old file name to new name (same file).htaccess 将旧文件名重定向到新名称(同一文件)
【发布时间】:2018-03-08 15:24:59
【问题描述】:

目前,这是我的 .htaccess 设置

RewriteRule ^buy-things-online plans5.php [NC,L]

当用户访问https://example.com/buy-things-online 时效果很好,他们确实看到了plans5.php 并且页面 URL 显示为https://example.com/buy-things-online

我的问题是当用户访问真实页面 https://example.com/plans5.php 时,他们不会被重定向到该页面的新名称(同一文件)

我尝试使用 301 重定向 这只是导致了一个循环,因为它是同一个文件并且浏览器说“重定向太多”

【问题讨论】:

标签: apache .htaccess


【解决方案1】:

您可以在站点根目录 .htaccess 中使用这些规则:

RewriteEngine On

# important to use THE_REQUEST that doesn't change after other rules
RewriteCond %{THE_REQUEST} /plans5\.php [NC]
RewriteRule ^ /buy-things-online [R=301,L]

RewriteRule ^buy-things-online plans5.php [NC,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 2015-10-09
    • 1970-01-01
    相关资源
    最近更新 更多