将单个页面重定向到另一个页面 - .htaccess

时间:2014-06-19 15:59:35

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

我尝试了从一个页面到另一个页面的不同重定向(页面移动到另一个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]

我只需要重定向某些网址,因为我把它们放在了类别中,而且很多网站都在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]

1 个答案:

答案 0 :(得分:0)

从我在代码中注意到的问题出现在这里:

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处理)这是实现它的方式。