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
https://forums.phpfreaks.com/topic/119359-quick-question-regarding-urls/
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?

 

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.

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.

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

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

Archived

This topic is now archived and is closed to further replies.

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