2016-10-06 87 views
1

我已经设置了一些301重定向在我的.htaccess文件...对于不存在的文件。他们的确在重定向,但增加了一个查询。例如:301重定向加入?页=

在我的htaccess文件中使用下面的一个重定向: 如果我输入example.com/about-example.php它应该将我重定向到example.com/about-example.html,它的种类是,但它需要我这个加?页面example.com/about-example.html?page=about-example.php =(重定向)和MOZ是看到重定向的页面查询末为重复的原始页面。

这里是我的htaccess的样子......(改变了很多例子/ 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内部错误..(编辑)我也搞砸了重定向的位置无济于事。

+0

我不完全理解你的问题,但你有一个特定的重写来做这个'RewriteRule ^(。+)\。html index.php?page = $ 1 [L]' –

+0

我会编辑我的主要评论到进一步解释。 – dhath

回答

0

你需要更新您的规则并在最后添加?。改为尝试这些规则。

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] 

让我知道这个答案适合你。

+0

嗨,谢谢你的帮助。所以我测试了它,它确实重定向到一个页面,但现在它有一个?在URL的末尾。这是否应该发生?另外,这是什么?实际上呢? – dhath

+0

@dhath在这里尝试使用重写。我修改了4条规则。 '?'告诉它删除任何查询字符串,如果它在请求中,不要追加它。 –

+0

我用重写,它只是去了404页面。 RedirectMatch 301的工作原理,只是想知道“?”在页面的末尾算作一个不同的页面导致重复的内容? 'RewriteRule^contact \ .php http://example.com/contact-example.html? [R = 301,L]'就是我所说的。 – dhath