Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress .htaccess not working for rewriterule

Can we rewrite WordPress page /ghij to show the contents of page /faq, when permalinks are already enabled?

My page is example.com?page_id=70&category=Footage. After enabling permalink it is showing example.com/video-category?category=Footage. I want it to look like example.com/category/Footage.

Any help in this will be appreciated.

Current .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
like image 669
Pankaj jarial Avatar asked Nov 04 '22 10:11

Pankaj jarial


1 Answers

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{QUERY_STRING} ^page_id=([0-9]*)&category=(.*)$
    RewriteRule ^(.*)$ /%1/%2? [R=301,L]

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

Works. And redirects from:
http://test.com/index.php?page_id=70&category=Footage
To:
http://test.com/70/Footage



UPDATED:

RewriteRule ^(.*)/(.*)$ /index.php?page_id=$1&category=$2 [L]


This rule Works and makes inner redirect (without url change) from:
http://test.com/70/Footage
To:
http://test.com/index.php?page_id=70&category=Footage

like image 152
StasGrin Avatar answered Nov 10 '22 21:11

StasGrin