L
L
Lici2013-04-02 10:52:15
PHP
Lici, 2013-04-02 10:52:15

Problem with 301 redirect?

There is an old site that has been ported to SimplaCMS. The URL structure has changed and you need to redirect from old pages to new ones.
The xtacses file looks like this: (redirects at the end itself)

AddDefaultCharset UTF-8
ErrorDocument 404 /404
ErrorDocument 401 /password.php
RewriteEngine on
# Admin is now at /simpla
RewriteRule ^admin/?$ simpla [L]
# Product catalog
RewriteRule ^catalog/([^/]+)/?$ index.php?module=ProductsView&category=$1 [L,QSA]
RewriteRule ^catalog/([^/]+)/([^/]+)/?$ index.php?module=ProductsView&category=$1&brand=$2 [L ,QSA]
RewriteRule ^products/([^/]+)/?$ index.php?module=ProductView&product_url=$1 [L,QSA]
RewriteRule ^products/?$ index.php?module=ProductsView [L,QSA]
RewriteRule ^brands/([^/]+)/?$ index.php?module=ProductsView&brand=$1 [L,QSA]
RewriteRule ^brands/([^/]+)/page_([^/]+)/?$ index.php?module=ProductsView&brand=$1&page=$2 [L,QSA]
# Search for products
RewriteRule ^search/([^/]+)/?$ index.php?module=ProductsView&keyword=$1 [L,QSA]
RewriteRule ^search/?$ index.php?module=ProductsView [L,QSA]
# Blog
RewriteRule ^blog/([^/]+)/?$ index.php?module=BlogView&url=$1 [L,QSA]
RewriteRule ^blog/?$ index.php?module=BlogView [L,QSA]
# Trash and orders
RewriteRule ^cart/?$ index.php?module=CartView [L,QSA]
RewriteRule ^cart/([^/]+)/?$ index.php?module=CartView&add_variant=$1 [L,QSA]
RewriteRule ^cart /remove/([^/]+)/?$ index.php?module=CartView&delete_variant=$1 [L,QSA]
RewriteRule ^order/([^/]+)/?$ index.php?module=OrderView&url=$1 [L,QSA]
RewriteRule ^order/?$ index.php?module=OrderView [L,QSA]
# For users
RewriteRule ^user/login/?$ index.php?module=LoginView [L,QSA]
RewriteRule ^user/register/?$ index.php?module=RegisterView [L,QSA]
RewriteRule ^user/logout/?$ index. php?module=LoginView&action=logout [L,QSA]
RewriteRule ^user/password_remind/?$ index.php?module=LoginView&action=password_remind [L,QSA]
RewriteRule ^user/password_remind/([0-9a-z]+) /?$ index.php?module=LoginView&action=password_remind&code=$1 [L,QSA]
RewriteRule ^user/?$ index.php?module=UserView [L,QSA]
# Google sitemap
RewriteRule ^sitemap.xml?$ sitemap.php [L,QSA]
# XML
RewriteRule ^yandex.xml?$ yandex.php [L,QSA]
# feedback
RewriteRule ^contact/?$ index.php?module=FeedbackView [L,QSA]
#downloads
RewriteRule ^order/([^/]+)/([^/]+)/?$ index.php?module=OrderView&url=$1&file=$2 [L,QSA]
# Static pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^/?$ index.php?module=MainView&page_url= [L, QSA]
# Resize images on the fly
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^files/products/(.+) resize/resize.php?file=$1&token=%{QUERY_STRING}
#RewriteCond %{THE_REQUEST} ^GET\ (.*)files/products/(.*)\?([A-z0-9]*)
#RewriteRule ^files/products/(.+) resize/resize.php?file= %2&token=%3 [L,NE]
#migration of old pages
Redirect 301 /product_49.html www.site.ru/products/ololo1
Redirect 301 /product_94.html www.site.ru/products/nashlemnaja_lolo
Redirect 301 /product_174.html www.site.ru/products/lololo2
Redirect 301 /product_64. html www.site.ru/products/tovar
Redirect 301 /product_66.html www.site.ru/products/product2
Redirect 301 /product_173.html www.site.ru/products/product3

However, when we navigate to /product_49.html, we get to products/ololo1 ?module=PageView&page_url= product_49.html
the same when using the syntax:
RewriteRule ^old_page.html$ /new_page [R=301,L]
What could be case? How to fix it? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
truekenny, 2013-04-02
@Lici

You have a rule # Статические страницы.
Put the code #перенос старых страницbefore it.

U
UZER2006, 2013-04-02
@UZER2006

I think that this rule still works

# Static pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^/?$ index.php?module=MainView&page_url= [L,QSA]

What happens if you remove the redirects and go to the same address /product_49.html?
Try to move the section #moving old pages above and after the redirect, also chop on [L]

L
LaFut, 2013-04-17
@LaFut

It's about priorities. As I understand ModRewrite, then ProxyPass and only then Redirect. Therefore, moving the redirect to any place in the htaccess file does not help me

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question