0

My URL works when the forward-slash is removed at the end I want to achieve mydomain.com/folder/parameter/. Currently, the 'mydomain.com/folder/parameter' URL is working for me.

Options +FollowSymLinks
RewriteEngine On  

# Redirect to non-www to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Rewrite for user.php?u=xxxxx 
RewriteRule ^city/([0-9a-zA-Z_-]+)?$ /city/index.php?u=$1 [NC,L]
RewriteRule ^information/([0-9a-zA-Z_-]+)$ /information/index.php?u=$1 [NC,L]
RewriteRule ^province/([0-9a-zA-Z_-]+)$ /province/index.php?u=$1 [NC,L]
  • Does this solves your question https://stackoverflow.com/questions/7780859/htaccess-rewrite-to-force-trailing-slash-at-the-end – Javapocalypse Feb 02 '22 at 07:23
  • 1
    Your patterns like `^city/([0-9a-zA-Z_-]+)?$` do not currently allow for a slash at the end. Add one inside the capturing group, and make it optional: `^city/([0-9a-zA-Z_-]+/?)?$` Be aware, that this will include the slash in the $1 value you pass to the scripts, if you don't want that, you need to place it outside the capturing group (careful, might allow `/city//` then), or use one more level of capturing, and fish the correct partial match out of there. – CBroe Feb 02 '22 at 07:33
  • @CBroe It is still giving HTTP ERROR 500. Please help. Now I'm using RewriteRule ^city/([0-9a-zA-Z_-]+/?)?$ /city/index.php?u=$1 [NC,L] – Nikhil Bachhav Feb 02 '22 at 08:41
  • What does the error log say? – CBroe Feb 02 '22 at 08:45
  • "Add one inside the capturing group" - you don't want to add the trailing slash _inside_ the capturing group (as you have done) since that changes the target URL (which you would need to allow for in your script). "careful, might allow `/city//`" - this is no more of an issue than with the current rule. "**still** giving HTTP ERROR 500" - were you getting a 500 error _before_? As @CBroe suggests, the details of the 500 error are in the server's error log - there doesn't seem anything obvious in the above rules. _Aside:_ Why are you preserving the protocol and not redirecting HTTP to HTTPS? – MrWhite Feb 02 '22 at 09:53
  • @CBroe and MrWhite - Thanks, Bro. Now, this regex is working. It was an issue in the PHP script not in htaccess. – Nikhil Bachhav Feb 03 '22 at 06:12

0 Answers0