【发布时间】: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] -
我将编辑我的主要评论以进一步解释。