Reputation: 9
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!
Upvotes: 0
Views: 83
Reputation: 9
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
Upvotes: 0
Reputation: 41219
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]
Upvotes: 1