Whats the easiest way to Re-direct example.com/user to example.com/user/profile.php? I need a way that my server can set up on its own - that is, when a user registers with my site, it automatically sets up a redirection in this manner, so that someone may access the users profile simply by typing example.com/user and not have to add all that extra stuff. My site is based on PHP, but this is a .htaccess issue isn't it? How can I write a PHP function to modify .htaccess and achieve this? Thanks
1.) use .htaccess and mod_rewrite # for example, rewrite /user/42 to /user/profile.php?id=42 RewriteEngine On RewriteRule ^/user/(\d+) /user/profile.php?id=$1 [L] Code (markup): 2.) yes ^^ 3.) since .htaccess is a file on your file system, you could read and write it with php (as long access belongs to you) but i would not recommend this way unless you really understand what you are doing with RewriteRules. Just edit your .htaccess file in the way shown at 1.) and you are done
Works great, thanks! Just so you know though, I removed the first slash in the RewriteRule, so its ^user/(\d+) after looking at other examples and such, because it wasn't working with the slash - but it works without it. Also changed other variables in it, but thanks for a good working example!