Need to stop old links from going to home page

I am moving a site to WooCommerce which uses different url's that my old Prestashop site.  I have found that the old url's are going to the home  page instead of showing a 404.  I need to remove whatever is going to the home page.  This is because I want to run to find the broken links.  However, they aren't showing up because they are going to the home page automatically.

This is the .htaccess in the public directory where wordpress resides

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Open in new window

Please tell me how to get these old links to show a 404.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That bit of code is standard for Wordpress sites. Basically, it says, "If a request comes in for a file that doesn't physically exist on the disk, then send the request over to index.php and let it take over from there."

This is critical for most Wordpress sites, since you usually have shortcodes and permalinks that rely on this routing code in order to work (because the pages only exist inside the database).

So if you remove this code, it's going to probably break a lot of other stuff.

If you can provide some examples of the bad URLs, there may be a way to specify an exception so that those specific URLs show a 404 instead.
sharingsunshineAuthor Commented:
the majority of them take either form:[any number]

/index.php?controller=cms&id_cms=[any number]
For a Wordpress site?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

sharingsunshineAuthor Commented:
those are links from my prestashop site, that I am converting from, that should show a 404
NerdsOfTechTechnology ScientistCommented:
I recommend to avoid 404 at all costs and suggest that you make a catch-all and/or do 301 "Moved Permanently" redirects to preserve your SEO 'ranking'. This catch-all looks to be done by Wordpress' default htaccess.

However, if you need to stop the catch-all to do the testing you mentioned, try commenting out the lines temporarily:

# BEGIN WordPress
#<IfModule mod_rewrite.c>
#RewriteEngine On
#RewriteBase /
#RewriteRule ^index\.php$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]

# END WordPress

Open in new window

Warning: this stops your WordPress from working correctly while you are testing.

The better way of doing this is to gather the links you had, and 301 them to the new links you will create. In other words, a 1:1 permanent redirect. Widget #1 on your old site gets redirected to Widget #1 on your redesign.
Ah, I see. Sorry, I somehow thought it was the other way around - you were moving TO Prestashop. That makes more sense now.

So in this case, what I would do is first add these 2 lines right after RewriteEngine On:
RewriteCond %{QUERY_STRING} ^controller=cms&id_cms=(.*)$ [NC]
RewriteRule . /presta2woo.php?id_cms=%1 [L]

Open in new window

That will look for something like this:
...and will redirect it to a new PHP script called presta2woo.php along with the original id_cms value.

Then you can build presta2woo.php like this:
// Redirect old Prestashop requests to new WooCommerce pages

// Get the original id_cms value
$id_cms = (isset($_GET["id_cms"]) ? intval($_GET["id_cms"]) : 0);

// Define the map
$map = array();
$map[123] = "index.php/your_woocommerce_stuff_here_for_product_123/";
$map[456] = "index.php/your_woocommerce_stuff_here_for_product_456/";

// Abort with a 404 if we don't have a mapping for that ID
  header("HTTP/1.0 404 Not Found");

// Otherwise, redirect the browser to the new page and return the 301 status code to let search engine spiders know this is the new URL to avoid SEO loss
header("Location: " . $map[$id_cms], true, 301);

Open in new window

If you just want all the old Presta URLs to return 404s and not even map to the new WooCommerce versions, then leave $map as a blank array. Otherwise, just map the old id_cms values to the appropriate new WooCommerce URLs, and the script will take care of redirecting with a 301 status code to avoid SEO loss.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sharingsunshineAuthor Commented:
Thanks for the help and the code.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Search Engine Optimization (SEO)

From novice to tech pro — start learning today.