简体   繁体   中英

Wordpress .htaccess 301 redirect or Rewriterule for plugin path

Very simple yet very confusing for me situation. I have a plugin on wordpress which generates dynamic results in a link as

www.mywebsite.com/testing/myname/1239812398123

I would like to use 301 to change this to:

www.mywebsite.com/myname/1239812398123

Please keep in mind that /1239812398123 will be dynamically generated therefore always different.

I already tried:

Redirect 301 /test/ /www.mywebsite.com/myname/

or

RewriteEngine On
RewriteRule ^test/myname/$ /myname/? [L,R=301]

But nothing works :(

Thanks!

Your uri pattern ^test/myname/$ matches when the uri is exactly /test/myname/ it does't match /test/myname/12389... , Modify your rule like this :

RewriteEngine On
RewriteRule ^test/myname/([0-9]+)/?$ /myname/$1 [L,R=301]

Ok i found that dynamic part is letters and numbers so i modified the code:

RewriteEngine On RewriteRule ^testing/myname/([a-z0-9]+) /myname/$1 [L,R=301]

And it works but I also discovered that this will throw an error message from the plugin - this path doesnt exist.

Is it possible to change only the main section but IF there is dynamic part - dont do anything

so it the situation:

  • if someone enter the main section www.mywebsite.com/testing/myname/ rewrite will be www.mywebsite.com/myname/

  • but if someone enter the dynamic section www.mywebsite.com/testing/myname/123lkj123 rewrite will not be triggered therefore it will remain the same www.mywebsite.com/testing/myname/123lkj123

Thanks

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