Web Hosting Talk







View Full Version : What ways are there to write clean URLS?


Shaliza
09-01-2005, 06:40 AM
I've never really had a problem making sites, but the clean URLS always seems to bring me to a halt.

I know that one way is to use mod_rewrite & even I'm a little confused on that. Are there any other ways? Because I'd like to have my links go from site.com/directory/page.php to site.com/directory/page.

Keep in mind that I do not have any id=12/category=12 like links.

WO-Jacob
09-02-2005, 03:47 AM
What I do is this...

/module/<id>/whatever/pretty/text/here/is/not/read/anyway.html

and just use:

RewriteRule module\/([0-9]+)/.* module.php?module_piece=$1

:D

Shaliza
09-02-2005, 04:21 AM
What if you're not using modules/id's though? I just have regular links.

I was thinking...is it possible to put the PHP force code in the htaccess file & just make all the pages site.com/directory/page manually?

WO-Jacob
09-02-2005, 04:32 AM
Ugh, that'd be horrible to have the pages have to actually exist. It would make it really... really... not fun to handle.

Shaliza
09-02-2005, 04:47 AM
That's true...

BigBison
09-02-2005, 07:47 AM
Shaliza, if you aren't using query strings (?id= and such) then this is really quite simple. Edit your pages so you're linking to /page instead of /page.php, then enable content negotiation. If page.php exists, it will be served when /page is requested. Cake.

http://httpd.apache.org/docs/1.3/mod/mod_negotiation.html

Dropping the filename extensions from URLs is definitely a good practice, more people should do this. :)

WO-Jacob
09-02-2005, 12:02 PM
BigBison: doesn't matter much if it's all fluff anyway :)

In my setup, there is no /module/ directory... not even a module.php :) The directory is named something completely different, and everything after the record id is... purely junk. :D

Shaliza
09-02-2005, 05:07 PM
You have a point about dropping the filename. What if we wanted to change the filename extension to something else in the near future? We wouldn't have to go about editing every link.

Because I'm new at this part, I think I'm just going to have to Google content negotiation for step-by-step instructions...

Not only that, but I have a pretty large site, so I don't want the URLs to become too much of a hassle.

BigBison
09-03-2005, 03:26 AM
Originally posted by Shaliza
Because I'm new at this part, I think I'm just going to have to Google content negotiation for step-by-step instructions...

Just add the following line to your .htaccess file:

Options MultiViews

Remove the .php extension from /page.php, and try accessing /page with your browser. Use a file other than index.php to test with. If this doesn't work, open a support ticket with your host as some don't allow 'Options' in .htaccess, but that should be all there is to it.

Shaliza
09-12-2005, 04:27 AM
I read the link, but I don't think MultiViews is what I want.

I talked to someone & they said I could just use ForceType & don't add extentions to the pages.

Shaliza
09-15-2005, 04:56 PM
FT doesn't seem to be working. Does anyone know if this will have something to do with the fact that I'm using subdomains?

Shaliza
09-23-2005, 06:43 PM
I'm using FT for part of my site, but I'm wondering if anyone knows how to work it for the index page? I don't want it to say index.php, but just index.

However, if I leave the extension off, it just takes me to the directory. When I clicked on index, the page came up fine.

BigBison
09-24-2005, 07:45 AM
I'm still wondering why you're trying to use Force Type instead of Options Multiviews?

Shaliza
09-24-2005, 06:44 PM
Because I checked it out thoroughly & it's not what I needed.

Can someone else please answer the question?

BigBison
09-24-2005, 08:20 PM
So basically, your problem with doing this the right way is that I suggested it? Your hostility towards my efforts to help you in this and other threads has been noted, you needn't worry about me posting in your threads anymore.

:rolleyes:

Shaliza
09-24-2005, 09:26 PM
What hostility? If I wanted to ignore what you said, I wouldn't have even bothered reading your posts, period. Just because I said I didn't need Multiviews, you're starting to get an attitude about it? And you clearly wasn't going to answer my question about FT, which is why I asked for someone else to answer.

Lord have mercy. Some people are too touchy around here.

Virnox
09-24-2005, 10:42 PM
Originally posted by Shaliza

Can someone else please answer the question?
^ I think BigBison ment that ^. That could be considered hostile/rude to some.

BigBison
09-25-2005, 12:54 AM
Originally posted by Shaliza
Just because I said I didn't need Multiviews, you're starting to get an attitude about it? And you clearly wasn't going to answer my question about FT, which is why I asked for someone else to answer.

You asked for help, not knowing how to accomplish what you were after. I provided a perfectly workable solution. Suddenly you're an expert who knows my solution isn't what you need, despite the fact that what you're trying doesn't work. Instead of theorizing that my solution isn't what you needed, did you try it first?

Or, in lieu of that, you could share why FT is so important to you because I'm still of the opinion that it isn't the right solution. My opinion is qualified by over a decade configuring web servers. So it isn't that I won't answer your question about FT, it's that I still think you shouldn't hammer in screws. Your snippy responses to my proferred help have led to my attitude.

I'm only touchy when my voluntary help is met with ingratitude.