WordPress.org

Ready to get started?Download WordPress

Forums

Why my htacess rewrite return 404? (3 posts)

  1. wpfishman
    Member
    Posted 1 year ago #

    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

    Here is my .htaccess file

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

    but when I type http://www.domain.com/abc/products-12345 in browser, it redirect to http://www.domain.com/def/products-12345, but it show 404. I tried to add echo get_query_var('page_id'); in 404 page, it return 0. How to solve it?

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Use 301 Redirects not Rewrite Rules

  3. MickeyRoush
    Member
    Posted 1 year ago #

    What happens when you move this:

    RewriteRule ^abc/products-(.+)$ def/products-$1 [R=301,L]

    Below the WordPress permalink code or after the </IfModule>?

    Also, you only need to have "RewriteEngine On" once at the very beginning of your file.

Topic Closed

This topic has been closed to new replies.

About this Topic