Specific URL Rewriting with parameters in wordpress

I’m rewriting a website that was originally in Drupal and has very specific URL’s.
So, I need to rewrite all the original URL’s to the wordpress system + the parameters for my own-written plugins:

I need to get from this:

http://www.domain.com/param1/param2/param3/param4/param5/detail

To this:

http://www.domain.com/index.php/detail/?param=param5

If the last part of the url = “detailSOMETHING

I’ve tried this (and many variations on it):

RewriteRule ^/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([detail_]+.*)/?  \
  /wp1/index.php/detail/?gref=$5    [PT]

placed in front of the WordPress code in .htaccess, but all I get is my WordPress 404 page.

Any help is appreciated!!!!!

EDIT:

Full .htaccess added:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp1/
RewriteRule ^/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([detail_]+.*)/?  \
/index.php/detail/?gref=$5    [PT]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp1/index.php [L]
</IfModule>
# END WordPress

1 Answer
1

Based on the info in the comments, here’s my preliminary answer, hopefully helping to debug the issue rather than a fix as I can’t see enough info for that — not the OP’s fault, rewrite debugging is just a pain.

The rewrite rule is obviously passing something to WP but WP isn’t happy with it.

What I’d do is add some debugging code to your theme’s 404.php that can show you the URL called and also the URL that WP is failing to parse. That at least will let you see whether your rewrite rule is doing what you expect.

Two other points though:

1 – If you don’t move your own htaccess code outside WP’s BEGIN and END then your changes will be overwritten if ever your site performs a hard save of its rewrites.

2 – It might be seen as better practice to code rewrite rules for your old URL structure within WP as a plugin instead of rewriting in htaccess.

Leave a Comment