tomdelonge Posted August 12, 2008 Share Posted August 12, 2008 i'll make this quick. i'm hoping to have my site display the url like so: website.com/aboutus/ rather than website.com/aboutus.php basically, i want the addresses to end in a slash and not have file extensions. i've seen this on many site, and i like it. i know how to do it a simple way. index.php is always displayed at the root, so i could just have a bunch of folders named "about us" and "contact us" and then have index.php files in all of those. however, that would be confusing; i'd probably end up with about 10 - 15 files named index.php. if worst comes to worst, i'll have to do it that way. any ideas on how to do that in a better fashion? thanks! Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 mod_rewrite Quote Link to comment Share on other sites More sharing options...
tomdelonge Posted August 12, 2008 Author Share Posted August 12, 2008 that looks like exactly what i wanted. i'm reading up on it now. now for another question. since this is an apache configuration, do most hosting plans allow access to that? i've never had a server, so i don't know. i'm talking not "dedicated" hosting. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 Yes, you just drop it in a file named ".htaccess" inside the folder. Yes, the . is in the filename. Quote Link to comment Share on other sites More sharing options...
tomdelonge Posted August 13, 2008 Author Share Posted August 13, 2008 Okay. I've been reading this article: http://www.sitepoint.com/article/guide-url-rewriting/ Now, it says in this file: httpd.conf, to uncomment (remove the # signs) these lines: #LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c Then, in the same file, it says to put this: <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^/shortcut$ /complicated/and/way/too/long/url/here </IfModule> Which folder does the ".htaccess" file go? does it go in each folder in the directory structure? And what goes in that file? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 You don't need to do that stuff in httpd.conf EXCEPT for the first two lines where you uncomment them. Because you do the rewrites in .htaccess, which is basically a per-directory httpd.conf. So just put .htaccess in your web root directory and try something like: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [NC,OR] RewriteCond %{REQUEST_FILENAME} -d [NC] RewriteRule .* - [L] RewriteRule ^([a-zA-Z0-9\-_]+)$ $1.php Try it. Quote Link to comment Share on other sites More sharing options...
tomdelonge Posted August 13, 2008 Author Share Posted August 13, 2008 okay, i'm using "easyphp" on my computer for testing purposes. in the httpd.conf file, there's only the "load module" line so i can only uncomment that one. is the "add module" line somewhere else? i can't find it. do i just need to do the one? i tried it, but maybe my example is wrong. in the .htaccess file, i wrote: RewriteRule RewriteRule ^/index/ /index.php i'm just trying to make: localhost/index/ go to localhost/index.php did i perhaps write that part wrong? thanks. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Never heard of "easyphp". Are you on Linux or Windows? Also, just uncomment the LoadModule line, it should work I think. Then, in a .htaccess file, just put the stuff that I had EXACTLY as I had it and it'll rewrite any non-directory file that has no extension to the filename.php. >_< Quote Link to comment Share on other sites More sharing options...
tomdelonge Posted August 13, 2008 Author Share Posted August 13, 2008 i'm on windows. i put what you said, but what should happen? say i have a file called thisfile.php; should i be able to type in "localhost/thisfile/"? and have it go use that file? that doesn't work. i copied and pasted what you said in the htaccess. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Restart your server after uncommenting that line. Quote Link to comment Share on other sites More sharing options...
tomdelonge Posted August 13, 2008 Author Share Posted August 13, 2008 still didn't work. let's break this down. i copied your code and i've uncommented what i was supposed to. what should happen? shouldn't i just type "localhost/thisfile/" and get whatever "localhost/thisfile.php" would have shown? is that right? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Let me just test the rewrite rule that I gave on my server, hold on. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Okay, it works for me as long as I don't have a directory of the same name. Quote Link to comment Share on other sites More sharing options...
tomdelonge Posted August 13, 2008 Author Share Posted August 13, 2008 maybe it's a different problem. most likely i screwed something simple up. i have a folder called www, which is the root, and "localhost" leads to that. i don't have any other folders or directories in that one. i have a file called thisfile.php, and a file called .htaccess thisfile.php: <?php echo "hello"; ?> .htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [NC,OR] RewriteCond %{REQUEST_FILENAME} -d [NC] RewriteRule .* - [L] RewriteRule ^([a-zA-Z0-9\-_]+)$ $1.php and i removed the comment on that one line in the conf file. did i put something in the wrong spot? what should be the outcome of this code? shouldn't i be able to type in "localhost/thisfile/" and have it say hello? (instead of 404 not found). i don't know... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Remove the trailing slash or change the .htaccess to: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [NC,OR] RewriteCond %{REQUEST_FILENAME} -d [NC] RewriteRule .* - [L] RewriteRule ^([a-zA-Z0-9\-_]+)/?$ $1.php Quote Link to comment Share on other sites More sharing options...
tomdelonge Posted August 14, 2008 Author Share Posted August 14, 2008 still doesn't work. Quote Link to comment 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.