简体   繁体   中英

How to 301 redirect URL's with “index.php?” in a path?

I am trying to redirect old URLs that look like this: mysite.com/index.php?dispatch=products.view&product_id=30176 to new URL's that are SEO friendly and look like - mysite.com/category/product

I am using CS-Cart 4.3.1 with SEO add-on enabled, and when I have imported all the products and categories the URLs were automatically changed.

This add-on has 301 redirect functionality in admin, which enables me to create 301 redirects manually. However, something is wrong and it doesn't work with redirects that have "index.php?" in a path to start with.

I have tried redirecting old URLs without "index.php?" in a path - like: "dispatch=products.view&product_id=30176" to "mysite.com/category/product" and it works, page is being redirected. But this is not the correct URL that is indexed by Google and need redirecting.

I suspect the issue is somewhere in Rewrite Conditions or Rewrite Rules on htaccess file that were created by system upon activation of SEO add-on.

This is how it looks like:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
Options -MultiViews

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_URI} ^api/(.*)$ [or]
RewriteCond %{REQUEST_URI} .*/api/(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*api/(.*)$ api.php?_d=$1 [L,QSA]

RewriteCond %{REQUEST_URI} \.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff|yml|xml)$ [or]
RewriteCond %{REQUEST_URI} store_closed.html$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)\/(.*)$ $2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

</IfModule>

If anybody can think of a reason why the redirects are not working when "index.php?" is included in a path, I would greatly appreciate your help.

The built-in "301 redirects" feature does not support non-seo friendly URLs as old URL parameter. It means that you cannot use "index.php?dispatch=products.view&product_id=30176", but you can use "old_website_category/old_website_product" one.

To realize what you want, please add 301 redirects to the .htaccess file. Eg

RewriteCond %{QUERY_STRING} ^product_id=30176$
RewriteRule ^/?index\.php$ http://example.com/category/product? [L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM