0

I've been stuck on this forever. In order to change localhost/article.php?id=bryan to simply localhost/article/bryan or even localhost/bryan whatexact .htaccess code should I use?

Thanks guys, really appreciate all the help!

1 Answer 1

2

You can use this:

RewriteEngine On
RewriteRule ^article/([^/]*)$ /article.php?id=$1 [L]

This will re-write localhost/article.php?id=bryan to http://localhost/article/bryan

Or you can use:

RewriteEngine On
RewriteRule ^([^/]*)$ /article.php?id=$1 [L]

This will re-write localhost/article.php?id=bryan to http://localhost/bryan

Sign up to request clarification or add additional context in comments.

6 Comments

This still doesn't work since when I type in localhost/article/bryan it is giving me an internal server error.
Have you got re-write rules turned on? Your Apache configuration may not allow re-write rules. In your Apache config use the change the setting AllowOverride to AllowOverride all
Yes, I've got everything turned on since I wrote code earlier to negate .php extensions.
What type of server are you using? Can you post the HTTP server log? I have tested the RewriteRule at htaccess tester and it seems to work pretty well.
I have tested the RewriteRule on my Apache server and it works fine. Maybe you have not enabled mod_write?
|

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.