简体   繁体   中英

Redirect URL with mod_rewrite with variable

I am looking to get a rule setup to change one of my URL's. After much research I understand the basics of mod_rewrite . The trouble I am having is the dynamic URL that is being re written. I have outlined in as much detail possible the task and desired outcome.

I currently have a url that looks like this:

http://www.myndness.com/my-canvas/{username}/

The {Username} is variable depending on which user you click on.

What I need to do is add /?my_posts to the end of that URL. This will then display the posts module by default for all users.

So all the users will follow the same URL pattern:

/User1/?my_posts
/User2/?my_posts
/User3/?my_posts
/User4/?my_posts

Apologies if I have missed anything.

I am using WordPress and have access to all files on the server.

Try this:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^my-canvas/[^/]+/?$ $0?my_posts [R=301,L,NC]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM