htaccess rewriting user pretty url to perform query

Say I have a site mysite.com, which is a wordpress site.

I already have the following rewrite rules to remove index.php:

Read More
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

if I go to mysite.com/?blog_type=a-blog-type I get the proper page with only the blogs of that type

What I would like, is for the user to be able to type in mysite.com/blogs/a-blog-type/ and have that acutally do the query, but keep on displaying /blogs/a-blog-type/

I’ve looked at many similar answers on here, but most seem to make it so that it just redirects from the query, to the pretty url, which I don’t want, as the pretty url just leads to a 404 error as it’s not doing the query.

Thanks for the help.

Related posts

Leave a Reply

1 comment

  1. This rewrite rule will take any mysite.com/blogs/a-blog-type/ URL and rewrite it to mysite.com/?blog_type=a-blog-type. So mysite.com/blogs/a-blog-type/ would be displayed to the user, but mysite.com/?blog_type=a-blog-type will be loaded.

    RewriteRule ^blogs/([^/]*)((/)?)$ ?blog_type=$1 [nc,l]
    

    EDIT: So here’s how your config will now look:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^blogs/([^/]*)((/)?)$ ?blog_type=$1 [nc,l]
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>