Bruce
Bruce

Reputation: 1071

htaccess rewrite remove trailing slash

I have the following rewrite rules which work perfectly

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\/$ /social/single_post.php?name=$1&t=$2&id=$3 [L]
RewriteRule ^([^/]*)\/$ /social/user.php?user=$1 [L]

Example: http://myurl.com/username/ points to http://myurl.com/social/user.php?user=username

I want to remove the trailing slash from the second rewrite rule so it will return as follows:

Example: http://myurl.com/username points to http://myurl.com/social/user.php?user=username

RewriteRule ^([^/]*)$ /social/user.php?user=$1 [L]

The problem is when I do this, the entire domain is redirecting

so: http://myurl.com/ points to http://myurl.com/social/user.php?user=

and http://myurl.com points to http://myurl.com/social/user.php?user=

Obviously I don't want those last two things happening. How can I modify my htaccess to achieve the desired outcome?

Upvotes: 0

Views: 94

Answers (1)

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try this,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\/$ /social/single_post.php?name=$1&t=$2&id=$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\/$ /social/user.php?user=$1 [L]

Upvotes: 1

Related Questions