1

I have a Wordpress page that receives a parameter in URL, like :

www.test.it/mypage/?param=1

and I would like to make it work using

www.test.it/mypage/1/

What do I have to write in .htaccess to achieve it?


Edit: I'm using Apache, the current mod_rewrite rules are these (default Wordpress rules):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
2
  • Set up rewrites in wp and see how it does it ^_^... Commented Sep 10, 2013 at 7:46
  • I already set it... the problem is I don't know how to work with a parameter and make it look like a subdirectory, and only on a specific page. Wordpress rewrites all the URLs, it's a more generic solution and I'd need a more specific one Commented Sep 10, 2013 at 7:53

2 Answers 2

2

So the solution is:

add_action( 'init', 'add_mypage_rule' );

function add_mypage_rule(){
    add_rewrite_tag("%param%", '(\d+)');
    add_rewrite_rule('^mypage/([^/]*)/?','index.php?pagename=mypage&id=$matches[1]','top');
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

    RewriteEngine on
    RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?param=$1 [QSA]

For more details

See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

Try this link

http://www.hongkiat.com/blog/wordpress-url-rewrite/

Hope this works

3 Comments

Unfortunately it doesn't work, maybe because of the pre-existing rules set by Wordpess?
The second link is very very helpful, +1. If I work it out I'll post the solution.
Were you ironic or what? Anyway, just posted it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.