Reputation: 512
I have a WordPress site and on one page we have a dynamic vimeo video embed. We use 2 url parameters to embed the video and set the page title.
We would like to rewrite this url so it appears to be directories instead of parameters
Current URL: /video?id=264243188&title=Testing
Desired URL: /video/264243188/Testing
Current .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} /video [NC]
RewriteCond %{QUERY_STRING} id=(.*)&title=(.*)
RewriteRule (.*) /video/%1/%2? [R=301,NE,L]
#RewriteEngine On
#RewriteRule ^video/([^/]*)/([^/]*)$ /video?id=$1&title=$2 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Upvotes: 0
Views: 81
Reputation: 675
You can have the below rewrite rule
RewriteCond %{REQUEST_URI} /video [NC]
RewriteCond %{QUERY_STRING} id=(.*)&title=(.*)
RewriteRule (.*) /video/%1/%2? [R=301,NE,L]
Working example for the same is at .htaccess tester
It redirects http://example.com/video?id=264243188&title=Testing
to http://example.com/video/264243188/Testing
And if in case you wanted to convert path to query string you can use the below rewrite rule
RewriteRule ^video/([^/]+)/?([^/]+)/? video?id=$1&title=$2 [R=301,NE,L]
Upvotes: 1