Jump to content

quick question regarding urls


tomdelonge

Recommended Posts

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!

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. >_< 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.