Ketan Lathiya
Ketan Lathiya

Reputation: 732

change query string url using htaccess in wordpress

I want to change url structure of page in wordpress

from:http://example.com/page-name/?id=rd123

to:http://example.com/page-name/rd123/

I have tried below code in .htaccess, I am getting ID if i use id numeric(123), but I am getting 404 page not found error if use id alphanumeric(rd123).

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page-name/([a-zA-Z0-9-]+)/?$ pagename.php?id=$1 [L]
</IfModule>

what i am missing in above code, it is in wordpress and i am not getting any perfect solution. here, page-name is template.

Upvotes: 3

Views: 957

Answers (2)

Mahendra Pumbhadiya
Mahendra Pumbhadiya

Reputation: 290

Try This,

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^page-name/(.*)/?$ page-name/index.php?id=$1 [L,QSA,NC]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
# END WordPress

Upvotes: 0

Croises
Croises

Reputation: 18671

In this case, use:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page-name/([a-zA-Z0-9-]+)/?$ page-name/index.php?id=$1 [L]
</IfModule>

It's not a problem with alphanumeric...

Upvotes: 1

Related Questions