0

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?

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

this helped so much thank you. It wasn't the exact result, but the condition statements definitely got me sorted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.