slj90 Posted January 1, 2016 Share Posted January 1, 2016 There are 2 parts to my question. Firstly, To view a users profile on my site you can type this: www.website.com/username I now want to do the same thing with the gallery page. Like this: www.website.com/gallery/username My question is, do I need to put the gallery.php page in a folder called 'gallery' or do I just need to have the gallery.php page in the htdocs main folder? My .htaccess currently reads RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1 What do I need to add to it so that gallery works too? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/300088-htaccess-help-hiding-username/ Share on other sites More sharing options...
requinix Posted January 2, 2016 Share Posted January 2, 2016 You can put gallery.php anywhere you want. In the main folder makes the most sense. I'm making a couple changes: RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9_-]+)/?$ profile.php?username=$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^gallery/([a-zA-Z0-9_-]+)/?$ gallery.php?username=$1 [L]1. Note the two (pairs of) RewriteConds: they make sure that you don't accidentally rewrite from an existing file or (more likely) directory.2. Most of the time you should use the [L] flag so that when one rewriting rule matches it will stop processing the rest of the rules and immediately go with the new URL you told it to use. And a suggestion: decide whether you want to officially have trailing slashes or not - don't do both. You can still redirect from one to the other, of course. Something like RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ $1 [L,R=301]should be able to handle redirecting away from a trailing slash for pretty much anything you have. Directories still need the trailing slash so those aren't affected. Quote Link to comment https://forums.phpfreaks.com/topic/300088-htaccess-help-hiding-username/#findComment-1528960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.