Reputation: 9476
I'm struggling with an htaccess rule at the moment - my knowledge of htaccess is rather rusty.
I want to internally rewrite (ie no redirect) a URL that contains a hash from
http://example.com/resources/3d/35d891df36cc4f08e10915e267ff54e4/index.php
to http://example.com/3d/resources/35d891df36cc4f08e10915e267ff54e4/
in order to work around a really crappy implementation in some legacy code. I've written the following rule to do the redirect:
RewriteCond %{REQUEST_URI} ^/resources/3d/([a-zA-Z0-9]+)/index.php$
RewriteRule /3d/resources/$1 [NC]
However, while the first part is matching, the second is not, and I can't see where I've gone wrong. Can anyone else point out the error?
Htaccess tester link here
Upvotes: 1
Views: 231
Reputation: 4897
You were really close to getting this to work. So I've made two small changes to make this work:
RewriteCond %{REQUEST_URI} ^/resources/3d/([a-zA-Z0-9]+)/index.php$
RewriteRule ^ /3d/resources/%1? [NC]
Adding ^
to the rewrite rule and changing $1
to %1
. Your use of $
was grabbing the resources directory again and not the query, changing this to %1
fixes this. I've added ?
to stop any further queries from being added to the end of the URL.
Testing Link -> Here
Upvotes: 1