Vamsi Mohan Jayanti Vamsi Mohan Jayanti - 18 days ago 8
Apache Configuration Question

How to write this URL rewrite rule to trucate unwanted content?

Iam using apache mod_rewrite to redirect some URL. I been able to some of the URLS but none of my rules are able to caprure this

http://192.23.70.11/mome/GIS%20Endo/%2Fhome%2FGIS%2520Endo%2F

and redirect it to

http://192.23.70.11/mome/GIS%20Endo/

Answer

You can use this rule as your first rule in site root .htaccess or Apache config:

# this goes in httpd.conf
AllowEncodedSlashes On

RewriteEngine On

RewriteRule ^(/?mome/[^/]+)/.+$ /$1 [L,NC,R=301,NE]

This will match any URI starting with /mome and will truncate anything after 2nd path component.

Comments