Reputation: 677
I want to rewrite URL using mod_rewrite in Apache server.
Specifically I want to rewrite URLs of the following form - mywebsite.com/web/ger/int/sb/index.html into mywebsite.com/gerintsb/
In the case of above URL ger, int, sb are appended together to form the shorter URL. I have many such URLs to be shortened.
I used the following RewriteRule in my .htaccess file inside the "web" folder in my server-
RewriteRule ^([a-z]+)([a-z]+)([a-z]+)$ web/$1/$2/$3/index.html [NC,L]
But my rule is not working. I am getting an object not found error.
Can someone troubleshoot?
Upvotes: 1
Views: 78
Reputation: 20745
[a-z]+
is greedy. It will consume the entire string. The second two capture groups will not catch anything. If a slash is at the end of the path your rule will not match.
You can only do this if you know the possible values of the path segments, or if the path segments have a fixed width:
RewriteRule ^(ger|fr)(int|float)(sb|mp|rt)/?$ web/$1/$2/$3/index.html [L]
or:
RewriteRule ^([a-z]{3})([a-z]{3})([a-z]{2})/?$ web/$1/$2/$3/index.html [L]
Upvotes: 2