v0idless
v0idless

Reputation: 948

Rewrite GET Variable in URL

I am using WordPress's permalink structure %category%/%postname%/ with the following htaccess:

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

The url's take the form http://www.example.com/category/postname/. I have a plugin where if you append ?m=gallery to the URL it will bring you to the posts' gallery. So http://www.example.com/category/postname/?m=gallery brings you to the gallery. I would like to be able to use http://www.example.com/category/postname/gallery/ instead. What do I need to modify in my htaccss to achieve my desired results? I would imagine it would be something like this RewriteRule ^(.+)/gallery$ $1?m=gallery

Edit - Current htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.+)/gallery/$ $1/?m=gallery [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Upvotes: 0

Views: 706

Answers (1)

LazyOne
LazyOne

Reputation: 165501

Considering URL example you have provided (http://www.example.com/category/postname/gallery/ => http://www.example.com/category/postname/?m=gallery) you will need this sort of line:

RewriteRule ^(.+)/gallery/$ $1/?m=gallery [QSA]
  1. Added missing slashes /

  2. Added [QSA] flag (may not be really necessary actually).

You would need to put this rule somewhere on the top: after this line, for example: RewriteRule ^index\.php$ - [L]

Obviously, you ensure that WordPress will generate this kind of URLs: http://www.example.com/category/postname/gallery/

Upvotes: 1

Related Questions