Reputation: 2609
I am not good at Apache URL Rewriting. I want do some rewrite here.
http://www.mydomain.com/item/search?words=something&number=1
=>
http://www.mydomain.com/item/search/something/1
And also should be avoid http://www.mydomain.com/search/something/1
=> http://www.mydomain.com/item/search/something/1
(If there has no /item/
add it)
Here is my rewrite code.
RewriteRule ^search/(.*)/(.*)/?$ /item/search/$1/$2 [L,R=301]
RewriteRule ^(item/search)/([^/]+)/(\d+)/?$ item/search?words=$2&number=$3
It show 404
:(
UPDATE: here is all my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^comment/(\d+)/?$ /post/comment/$1 [L,R=301]
RewriteRule ^(post/comment)/(\d+)/?$ post/comment?comment=$2
RewriteRule ^rss/(.*)/?$ /item/rss/$1 [L,R=301]
RewriteRule ^(item/rss)/(.*).xml/?$ item/rss.php?rss=$2
RewriteRule ^search/(.*)/(.*)/?$ /item/search/$1/$2 [L,R=301]
RewriteRule ^(item/search)/([^/]+)/(\d+)/?$ item/search?words=$2&number=$3
RewriteCond %{http_host} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Upvotes: 0
Views: 945
Reputation: 1333
you can not do it in htaccess
, you should add some code in your wordpress theme function.php
.
function add_my_rewrite() {
add_rewrite_rule('^item/search/(.+)/(\d+)?$', 'index.php?pagename=item/search&words=$matches[1]&number=$matches[2]', 'top');
}
add_action( 'init', 'add_my_rewrite' );
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
Upvotes: 1