I have the following working rule : RewriteRule (.*)-sample/id/([^/]+)$/(.*) http://www.example.com/$1-sample/id/$2/ [R=301,L]
The above code helps me add a slash to the end of the URL Eg1 : http://www.example.com/INK-sample/id/70001452 changes to http://www.example.com/INK-sample/id/70001452/ Eg2 : http://www.example.com/FILTER-sample/id/70001456 changes to http://www.example.com/FILTER-sample/id/70001456/
But when i type http://www.example.com/FILTER-sample/id/70001456/rubbishcharacter213342 , the URL does not change to http://www.example.com/FILTER-sample/id/70001456/ The page display right content but the URL is wrong - http://www.example.com/FILTER-sample/id/70001456/rubbishcharacter213342
How do i automatically truncate all 'rubbishcharacter213342' (any character after the last slash) from the URL automatically and change URL to http://www.example.com/FILTER-sample/id/70001456/
The $ symbol means "end", so you can't have one of those in the middle of a RegEx pattern.
The (.*) patterns cause your code to attempt tens of thousands "back off and retry" trial matches per URL request. This is very very slow and inefficient. At least the leading (.*) pattern should be changed to something else.
Finally, URLs for folders and for the index page of a folder should end in a trailing slash. The URL for a page should not have a trailing slash and may or may not have an extension.
IF all the URLs to be redirected have /id/ in them, something like this might work.