i'm working with mod_rewrite under .htaccess, and i'm trying to fore adding a slach "/" to the end of the url :
interpret this url : http://domain/ABC/DEF
like this http://domain/ABC/DEF/
how can i write the rule please ?
i'm working with mod_rewrite under .htaccess, and i'm trying to fore adding a slach "/" to the end of the url :
interpret this url : http://domain/ABC/DEF
like this http://domain/ABC/DEF/
how can i write the rule please ?
To add a trailing slash at the end of Request_uri, You can use the following rule in htaccess :
RewriteEngine On
#If there is already a trailing slash, skip the rule.
RewriteCond %{REQUEST_URI} !/$
#else redirect any request to add a trailing slash
RewriteRule ^(.+)$ /$1/ [L,R]
This automatically adds a trailing slash and changes the url
to
The RewriteCond is important here to avoid redirect loop error, without this condition a request for /foo redirects to /foo/ on initial iteration, On the second iteration the target url /foo/ matches the Rewrite pattern and redirects /foo/ to /foo/ and causes the loop error.
(Hope ,This helps!)