Jamie
Jamie

Reputation: 3

.htaccess rule to rewrite query string to a path

I'm looking for a way to have the URL site.com/collection/name serve the content that is actually located at... site.com/collection/?collection_name=name

The website is running on WordPress, and is currently using the default .htaccess rules located in the root:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Because it's on WordPress, it's currently looking for a page /collection/name that doesn't exist, and produces a 404 error.

Upvotes: 0

Views: 617

Answers (1)

Theo Orphanos
Theo Orphanos

Reputation: 1447

There should be an index file under the folder "name"

If so, you can try this:

RewriteEngine On
RewriteBase /
RewriteRule ^/$ /collection/name/index.php
RewriteRule ^([a-zA-Z0-9_-]+)/$ /collection/?collection_name=$1

This is a generic rule that works in many similar occasions. Modify it to suit your website...

Upvotes: 1

Related Questions