custom htaccess rewrite rule for page

i have a page in wordpress called “video”. its page id is 6, and its slug is “video”

in my theme ive set it up to show content based on GET variables

Read More

here is the URL rewrite im trying to set up:

heres the original URL with the GET variables inside:

mysite.com/video/?video_id=102230&video_title=FC+Emmen+v+AGOVV+Apeldoorn&video_src=MTAyMjMw

heres the URL i want it rewritten to so it can be indexed:

mysite.com/video/102230/MTAyMjMw/FC+Emmen+v+AGOVV+Apeldoorn

heres my htaccess file that is not working:

# BEGIN WordPress
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^video/(.*)/(.*)/(.*)$ ?page_id=6&7video_id=$1&video_src=$2&video_title=$3 [NC]
</ifmodule>
# END WordPress

what happens is, when i try and visit mysite.com/video/102230/MTAyMjMw/FC+Emmen+v+AGOVV+Apeldoorn, it simply automatically goes to mysite.com/video and removes everything after /video

edit – now it is not removing everything after /video, but its telling me “Nothing found for Video 102230 MTAyMjMw FC+Emmen+v+AGOVV+Apeldoorn”

Related posts

Leave a Reply

1 comment

  1. You can do this with WordPress’ built-in rewrite system.

    function add_video_rewrite() {
        add_rewrite_tag("%video_id%", '([^/]*)');
        add_rewrite_tag("%video_src%", '([^/]*)');
        add_rewrite_tag("%video_title%", '([^/]*)');
        add_rewrite_rule('^video/([^/]*)/([^/]*)/[^/]*)', 'index.php?pagename=video&video_id=$matches[1]&video_src=$matches[2]&video_title=$matches[3]', 'top');
    }
    add_action( 'init', 'add_video_rewrite' );
    

    Didn’t test it, but I think this should work.
    What is does is first adding tags that you can use in your template (get_query_var(video_id)). Then add a rewriterule that specifically matches the URL.

    You should put this code in your functions.php and then flush your rewriterules (go to setting > permalinks).

    More info about rewriterules for WordPress:
    http://codex.wordpress.org/Rewrite_API
    http://codex.wordpress.org/Rewrite_API/add_rewrite_tag
    http://codex.wordpress.org/Rewrite_API/add_rewrite_rule