Reputation: 134
I have some troubles removing the ids at the end of url. With the following snippet it sort of works but then all the assets such as css and js are not being loaded correctly.
Original url: http://mywebsite.com/poker-in-englisch/150/1448/98480
should be url: http://mywebsite.com/poker-in-englisch/
Here is my snippet:
RewriteEngine on
RewriteRule ^((?!([0-9]{3})\/([0-9]{4})\/([0-9]{5})).)*/ $1 [L,R=301]
Since the ids are always 3 number / 4 number / 5 numbers, I tried to catch everything before that with a negative look up and remove that. Unfortunately none of the css or js works afterwards... and my page looks sort of messed up.
Any help or hint appreciated
Upvotes: 0
Views: 84
Reputation: 133428
Could you please try following. Simply checking condition if REQUEST_FILENAME is not a file or directory in local system if yes then do rewriting the rule. In RewriteRule
's regex in 1st capture group capturing everything before 1st occurrence of /
in group 1 and then mentioning digits 3 4 and 5 as per question. On substitution part of url rewriting by mentioning $1
it will rewrite the uri to first captured part.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/\d{3}/\d{4}/\d{5}/?$ /$1 [L]
Upvotes: 2