Redirect of URL with parameters to URL without — plus WordPress

I have rebuilt a website that used some custom php to serve up individual store pages with urls like this:

http://thedomain.com/storedetails.php?storeNum=1

The new site is powered by WordPress, and each individual store will live in a named subdirectory, like this:

Read More
http://thedomain.com/stores/gothamcity

I have been trying solutions I have found on stackoverflow that all seem to be variations on this: 301 Redirect of old url with parameters to a path without parametes

Here’s an example:

RewriteCond %{QUERY_STRING} ^storeNum=18$ [NC]
RewriteRule ^/storedetails.php$ http://www.thedomain.com/stores/gothamcity? [L,R=301]

But so far nothing works. I continue to get “page not found” 404 error pages in WordPress.

My best guess is that something in WordPress’s part of the .htaccess is throwing this off? Here’s what they include:

# 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]
</IfModule>
# END WordPress

Can anyone help?

Related posts

Leave a Reply

1 comment

  1. This should work:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{QUERY_STRING} ^storeNum=18$ [NC]
    RewriteCond %{HTTP_HOST} .*
    RewriteRule ^storedetails.php http://www.thedomain.com/stores/gothamcity? [L,R=301]
    
    RewriteRule ^index.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    I suggest you use a RewriteMap though to map store numbers to names.