【问题标题】:Redirection of single pages to another page - .htaccess将单个页面重定向到另一个页面 - .htaccess
【发布时间】:2014-08-10 06:10:48
【问题描述】:

我尝试了从一个页面到另一个页面的不同重定向(页面移动到另一个 url),但没有任何效果 - 我不断收到 404 页面。

我想将http://www.staskka.com/mladinska-postelja-gasilec.html 移动到http://www.staskka.com/otroska-oprema/otroske-posteljice/mladinska-otro%C5%A1ka-postelja-gasilec.html

什么都没有发生。仍然找不到 404 页面。

.htaccess 中的代码是:

# BEGIN Permanent URL redirects

RewriteRule ^mladinska-postelja-gasilec\.html$ /pohistvo/otroske-posteljice/mladinska-otroška-postelja-gasilec/? [L,R=301,NC]

我也有从非 www 重定向到 www.. 并且工作正常..

RewriteCond %{HTTP_HOST} !^www\.

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

我只需要重定向一些 URL,因为我将它们放在类别中,并且很多此类网站在 google 上的排名都非常好——有人可以帮帮我吗?

非常感谢您的帮助..谢谢。

哦,我使用的是 OC 1.5.1.3。

编辑:这是整个 .htaccess

    rewriteengine on


rewritecond %{HTTP_HOST} ^www.djecje-kuhinje.com$ [OR]
rewritecond %{HTTP_HOST} ^djecje-kuhinje.com$
rewriterule ^djecje-kuhinje-com\/ "http\:\/\/shop\.djecje-kucice\.com\/" [R=301,L] #52b5421b82424
rewritecond %{HTTP_HOST} ^www.otroska-kuhinja.si$ [OR]
rewritecond %{HTTP_HOST} ^otroska-kuhinja.si$
rewriterule ^otroska-kuhinja\/ "http\:\/\/www\.otroskekuhinje\.si\/" [R=301,L] #51f13a48f336e
rewritecond %{HTTP_HOST} ^kidkraft.staskka.com$
rewriterule ^kidkraft\/ "http\:\/\/www\.staskka\.com\/" [R=301,L] #50f3d3a25618d



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

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* – [F,L]




##BEGIN MOBILE (do not edit below this line)
RewriteBase /
##END MOBILE
rewriterule test\.htm http://www.google.com [R]
rewritecond %{HTTP_USER_AGENT} ((.*iPhone.*)|(.*iPod.*)|(.*BlackBerry.*)|(.*Android.*Mobile.*)|(.*Windows\ CE.*)|(.*IEMobile.*)|(.*Opera\ Mini.*)|(.*Opera\ Mobi.*))
rewritecond %{HTTP_COOKIE} !dm_show_classic
rewritecond %{QUERY_STRING} !no_redirect=true [NC]
rewritecond %{HTTP_HOST} ^www\. [NC,OR]
rewritecond %{HTTP_HOST} ^[0-9a-z-]+\.[a-z]+$ [NC]
rewritecond %{REQUEST_URI} ^/_dm/s/ [NC,OR]
rewritecond %{REQUEST_FILENAME} !\.(jpg|gif|png|css|js|txt|ico|pdf|bmp|tif|mp3|wav|wma|asf|mp4|flv|mpg|avi|csv|doc|docx|xls|xlsx|ppt|pptx|zip|rar|tar|gz|dmg|iso)$ [NC]
rewriterule ^(.*)$ http://mobile.staskka.com/ [R,L]
rewriterule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
rewriterule ^googlebase.xml$ index.php?route=feed/google_base [L]
rewriterule ^download/(.*) /index.php?route=error/not_found [L]
rewritecond %{REQUEST_FILENAME} !-f
rewritecond %{REQUEST_FILENAME} !-d
rewritecond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
rewriterule ^([^?]*) index.php?_route_=$1 [L,QSA]


# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/x-javascript "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
ExpiresDefault "access plus 1 week"
</IfModule>
## EXPIRES CACHING ##

<ifModule mod_gzip.c>

mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

</ifModule>




# BEGIN Permanent URL redirects
RewriteRule ^mladinska-postelja-gasilec\.html$ /pohistvo/otroske-posteljice/mladinska-otroška-postelja-gasilec/? [L,R=301,NC]
RewriteCond %{SCRIPT_FILENAME} !-s
RewriteRule (.*) index.php?path=$1 [QSA,L]

【问题讨论】:

  • 您可以在问题中发布完整的 .htaccess 吗?
  • 如果您使用的是 Opencart,则需要在所有其他重定向规则之后在底部添加自定义重定向规则,否则您可能会收到这些特定错误。所以发布完整的重定向块可以帮助解决这个问题。
  • 是的,当然..我无法在评论中添加代码..我将在下面的问题中添加它

标签: .htaccess redirect http-status-code-404 opencart http-status-code-301


【解决方案1】:

从我在代码中注意到的问题在于:

rewriterule ^([^?]*) index.php?_route_=$1 [L,QSA]

由于有一个 L 标志,这意味着在 url 调用之后,服务器对其进行处理并在那里结束,这意味着如果 url 在上述条件中被捕获,那么你之后写的任何内容都会停在那里。

因此,在您的具体情况下,您需要添加(注意没有 L 标志的情况相同,因为您需要 Opencart 之后对其进行处理):

RewriteRule ^mladinska-postelja-gasilec\.html$ /pohistvo/otroske-posteljice/mladinska-otroška-postelja-gasilec/? [R=301,NC]

在这行之后

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* – [F,L]

让我澄清一下,我不确定您使用的代码是否与您想要的行为相匹配。但立场是正确的。此外,由于在我的评论中我声明您需要在最后添加这些规则,这主要用于处理外部域,对于您的情况(内部 url 处理),这是实现它的方式。

【讨论】:

  • 谢谢乔尼德。它有一点帮助,但正如你所说,不是正确的位置。它将我重定向到该类别,但浏览器中的 uRL 没有改变 - 它保持不变:staskka.com/mladinska-postelja-gasilec.html
  • 嗯,试试 L 标志:RewriteRule ^mladinska-postelja-gasilec\.html$ /pohistvo/otroske-posteljice/mladinska-otroška-postelja-gasilec/? [L,R=301,NC] ,再次考虑这个 L 标志是必需的,因为您现在看到的行为意味着服务器存在重定向,但由于允许进一步处理,服务器识别它。像以前一样尝试使用 L 标志并告诉我结果。
  • @ideep13 请查看我的评论并告诉我结果。
  • 好吧,网址更改为staskka.com/pohistvo/otroske-posteljice/…,但我仍然看到类别
  • @ideep13 很高兴我能帮上忙 :),如果你觉得答案值得,那就接受吧:)
猜你喜欢
  • 1970-01-01
  • 2016-12-19
  • 1970-01-01
  • 2014-09-01
  • 2016-07-20
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多