-1

Here is my .htaccess file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^abc/products-(.+)$ def/products-$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>

I have many url links in /abc/ sub-directory, like

http://www.domain.com/abc/products-12345
http://www.domain.com/abc/products-23456
http://www.domain.com/abc/products-34567
http://www.domain.com/abc/new-items

Now I want to url rewrite /abc/products- to /def/products-

http://www.domain.com/def/products-12345
http://www.domain.com/def/products-23456
http://www.domain.com/def/products-34567
http://www.domain.com/abc/new-items

the code: RewriteRule ^abc/products-(.+)$ def/products-$1 [R=301,L] could make the page redirect, but the it when type http://www.domain.com/abc/products-12345 the browser will go to http://www.domain.com/def/products-12345 but the page show as 404. If I remove it, http://www.domain.com/abc/products-12345 could run well. Why and How to? Thanks.

Update:

I have moved RewriteRule ^abc/products-(.+)$ def/products-$1 [R=301,L] ahead of RewriteRule ^index\.php$ - [L] still get 404. And I add echo get_query_var('page_id'); in 404.php, this return 0.

why the url could redirect but miss the right page?

1

I am assuming that the stuff in "def/products" is not handled by WordPress.

Try reversing the index.php and abc/products rules, like so:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^abc/products-(.+)$ def/products-$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>

.htaccess is read and executed line by line. It may help to have your rule execute before WordPress's. That is the way I usually handle it.

I say 'try' because I can usually get these to work but sometimes not the first time. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.