【问题标题】:301 redirects are adding ?page=301 重定向正在添加 ?page=
【发布时间】:2017-02-15 11:09:13
【问题描述】:

我已经在我的 .htaccess 文件中设置了一些 301 重定向...用于不存在的文件。他们确实在重定向,但添加了查询。例如:

在下面的 htaccess 文件中使用我的重定向之一: 如果我输入 example.com/about-example.php,它应该将我重定向到 example.com/about-example.html,它有点像,但它会将我带到 example.com/about-example.html?page=about -example.php 添加了这个 ?page=(redirect) 并且 moz 看到该重定向页面在末尾带有一个查询作为原始页面的副本。

这是我的 htaccess 的样子...(对 example/xyz 进行了很多更改)

Options -Indexes +FollowSymLinks

RewriteEngine on
RewriteBase /

# Remove "www."
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Redirect any requests for html files to index
RewriteRule ^(.+)\.html index.php?page=$1 [L]

# Rewrite any request for subdirectories to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]

## SITE REFERRER BANNING
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)*example\.net/ [NC,OR]




## EXPIRES CACHING ##

# 6 month for most static assets
<filesMatch ".(jpg|jpeg|png|gif|gs|ico)$">
Header set Cache-Control "max-age=1576800, public"
</filesMatch>

# 1 month for most static assets
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=2628000, public"
</filesMatch>

<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault                                      "access plus 1 month"

  # CSS
ExpiresByType text/css                              "access plus 1 year"

  # Data interchange
ExpiresByType application/json                      "access plus 0 seconds"
ExpiresByType application/xml                       "access plus 0 seconds"
ExpiresByType text/xml                              "access plus 0 seconds"

  # Favicon (cannot be renamed!)
ExpiresByType image/x-icon                          "access plus 1 week"

  # HTML components (HTCs)
ExpiresByType text/x-component                      "access plus 1 month"

  # HTML
ExpiresByType text/html                             "access plus 0 seconds"

  # JavaScript
ExpiresByType application/javascript                "access plus 1 year"

  # Manifest files
ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
ExpiresByType text/cache-manifest                   "access plus 0 seconds"

  # Media
ExpiresByType audio/ogg                             "access plus 1 month"
ExpiresByType image/gif                             "access plus 1 month"
ExpiresByType image/jpeg                            "access plus 1 month"
ExpiresByType image/png                             "access plus 1 month"
ExpiresByType video/mp4                             "access plus 1 month"
ExpiresByType video/ogg                             "access plus 1 month"
ExpiresByType video/webm                            "access plus 1 month"

  # Web feeds
ExpiresByType application/atom+xml                  "access plus 1 hour"
ExpiresByType application/rss+xml                   "access plus 1 hour"

  # Web fonts
ExpiresByType application/font-woff2                "access plus 1 month"
ExpiresByType application/font-woff                 "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
ExpiresByType application/x-font-ttf                "access plus 1 month"
ExpiresByType font/opentype                         "access plus 1 month"
ExpiresByType image/svg+xml                         "access plus 1 month"
</IfModule>


Redirect 301 /about-example.php http://example.com/about-example.html
Redirect 301 /vacation-faq.php http://example.com/faqs.html
Redirect 301 /3d-tour.html http://example.com/plans.html
Redirect 301 /images/cool/04.jpg http://example.com/gallery.html

我错过了一个命令,还是重定向在错误的位置?我已经尝试过重写规则、redirectmatch ...以及其他一些具有相同结果或 500 个内部错误的东西..(编辑)我也弄乱了重定向的位置,但无济于事..

【问题讨论】:

  • 我不完全理解你的问题,但你有一个特定的重写来做到这一点RewriteRule ^(.+)\.html index.php?page=$1 [L]
  • 我将编辑我的主要评论以进一步解释。

标签: apache .htaccess redirect


【解决方案1】:

您需要更新规则并在末尾添加?。试试这些规则。

Options -MultiViews
RewriteEngine on
#if request is a real file or dir do nothing
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

#else do these redirects
RewriteRule ^about-example\.php http://example.com/about-example.html? [R=301,L]
RewriteRule ^vacation-faq\.php http://example.com/faqs.html? [R=301,L]
RewriteRule ^3d-tour\.html http://example.com/plans.html? [R=301,L]
RewriteRule ^images/cool/04\.jpg http://example.com/gallery.html? [R=301,L]

让我知道这个答案对你有什么作用。

【讨论】:

  • 您好,感谢您的帮助。所以我用一个测试它,它确实重定向到一个页面,但现在它有一个?在 URL 的末尾。这应该发生吗?另外,什么?真的吗?
  • @dhath 在这里尝试使用重写。我修改了4条规则。 ? 告诉它删除任何查询字符串,如果它在请求中,则不要附加它。
  • 我使用了重写,它只是进入了 404 页面。 RedirectMatch 301 有效,只是想知道“?”在页面的末尾算作不同的页面导致重复的内容? RewriteRule ^contact\.php http://example.com/contact-example.html? [R=301,L] 是我写的。
  • 我的意思是?在 URL 而不是页面的末尾。
  • 你重定向到的页面是真实页面吗?
猜你喜欢
  • 2012-10-18
  • 2014-04-04
  • 2016-11-21
  • 1970-01-01
  • 1970-01-01
  • 2013-12-14
  • 2018-10-21
  • 2012-10-07
  • 2013-01-09
相关资源
最近更新 更多