0

Please help me. I need to rewrite this url

http://example.com/topusers.php?sort=post_count&time=month

into this style

http://example.com/top/post_count/month

I'm using this in .htaccess but when I visit example.com/top, it shows 404 Not Found.

RewriteRule ^top/([^/.]+)?/?(.*)$ topusers.php?sort=$1&time=$2

It needs to be accessible via example.com/top too, because I've set default values if sort and time are not set via URL.

Thank you.

1 Answer 1

2

You're requring slash after top in your rewrite rule.

RewriteRule ^top/?([^/.]+)?/?(.*)$ topusers.php?sort=$1&time=$
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer. If I want the slash at the end of URL to be optional (URL works fine with or without it), how do I alter the RewriteRule? :)
Thank you, but it's not working. Yes, it's accessible, but when I echo the variables, results are wrong. Example links: topusers.php?sort=post&time=all, With ^top/([^/.]+)?/?(.*)$ topusers.php?sort=$1&time=$2, sort = 'post', time = 'all' With ^top/?([^/.]+)?/?(.*)$ topusers.php?sort=$1&time=$2, sort = 'users', time = '.php'
your link in that case should be top/post/all - not topusers.php?sort=post&time=all

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.