2016-10-06 124 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