Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

Making "clean" URLs with Apache and PHP

Rated 4.07 (Ratings: 15) (Add your rating)

Log in to add a comment
(102 comments so far)

Want more?

 
Picture of notabene

Stephane Deschamps

Member info | Full bio

User since: March 19, 2002

Last login: April 14, 2008

Articles written: 4

Nowadays we almost systematically create database-generated websites. URLs are thus written on-the-fly and we usually call pages through query string, like:
http://example.com/index.php?type=article&id=25&date_written=20020322.

What I call "clean" URLs is what you can see on evolt.org, for instance. In my example the URL would be:
http://example.com/article/200203226.

Let us assume that this article was the 6th written on the 22nd of march, 2002 and that we store this info in our database, see below, Structuring your data). The purpose of this article is to show you how to switch from the former to the latter with Apache and PHP through a simple example.

Note: there's nothing polemic about this "clean" qualification. Anybody who finds a better name is welcome to use it instead...

What's the use of switching from query strings to "clean" URLs?

Dropping query strings and using these so-called "clean" URLs:

  • Enables indexing by search engines. As you probably know, when a search engine spiders your site and finds a query string it stops. After all, how on earth can the robot know that all the pages are not the same with just a different parameter passed to the page: what's the difference between index.php?type=article&id=25 and index.php?style=red? How can one expect a search engine to know the difference?
  • Makes for more perennial URLs. As Tim Berners-Lee himself explained in Cool URIs don't change, "It is the duty of a Webmaster to allocate URIs which you will be able to stand by in 2 years, in 20 years, in 200 years". You can see where we're aiming at.
  • Doesn't expose the server-side language in which you developed the site: No extension is provided, thus enabling you to switch from one server-side technology to another without generating multiple 404 errors. Moreover, as a side note, it's a bit more secure because it will take potential attackers more time to know what language you're using (but don't have too many illusions about that, the solution will eventually be found...)

Need we say more?

Structuring your data: creating unique identifiers

First and foremost, think of the data stored. You have to be able to give a unique identifier to each article. So instead of (or in addition to) using an incremental id you must think of a unique, not-to-be-changed-in-the-future identifier.

My method in our example is this: create a field uniqid and give it the date concatenated with the rank of creation within the day. In my example my article's uniqid is 200203226 (the article was the 6th created on the 22nd of March, 2002). Of course one can imagine a situation where only one article is written per day. Thus maybe this uniqid field is redundant if you store the date the article was written. Or it can be YYYYMMDDHHmmss to have the whole date and no rank. [insert here any other naming method you like].

Note: there are many other ways to store your articles. Maybe they're each in their own text file in a dedicated includes directory and then you call them through an inclusion, maybe they're extracted from an XML file, etc. That's why I'm not too specific on the storage of data here.

The 'article' file: parsing the URL

Now we will create the article file using standard PHP code, even if, as you noticed, the file has no .php extension. We'll come back to this issue below, in Using Apache's ForceType. Here's the code for our article file:

<?php
    /* 1. parse the URL */
    $expl = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
    $article_id = $expl[count($expl)-1];

    /* 2 security check */
    [omitted for the sake of simplicity]

    /* 3 populate the page with uniqid's content */
    [omitted for the sake of simplicity]
?>

Here's how it works:

  1. Parse the URL (REQUEST_URI) by exploding it, fetch the results in an array ($expl) and assing to $article_id the last occurence of the explosed array.
  2. Check any security needed and stop the code on error. There's no reason to parse the page any further if what's passed to $article_id is not correct. In particular we'll check the following:
    • Is $article_id valid? Does it really correspond to the format I'm looking for? For instance if I'm looking for a number of the form 'YYYYMMDDr' ('r' is the 'rank' in my example, remember?) and $article_id is a string (ie. 'foobarwhatever'), then there's something rotten in the kingdom of URLs.
    • Does $article_id compare to an existing value of uniqid?
    • In the case of a database-driven site: is there any database code passed through $article_id that could damage the database? Think of drop table instructions, for example.
    • [insert here any other security check you find necessary]
  3. Populate the page with the content corresponding to the uniqid equal to $article_id.

Using Apache's ForceType

At first I tried creating "clean" URLs and redirecting them through 404 errors to the index.php, for example, which would then parse the URL and write the page accordingly. I ran into unsuspected trouble checking my system with Lynx: a 404 error is an error (yeah, right). So I guessed search engines would stop on this error. Damn. My world domination (© glassdog) scheme goes down the drain.

Enter ForceType. This Apache directive forces the server to consider a file as being of another type than what is expected by default (see Apache's documentation on ForceType).

We will now use the &lt;FilesMatch&gt; directive to specify which file is to be considered as a PHP file and not a plain ol' text file, which is the default on most servers (see Apache's documentation on <FilesMatch>).

Don't worry: even if you can't configure Apache directly because your hosting provider doesn't allow it, I've got good news: you can do it through a .htaccess file.

Here's a sample .htaccess I wrote in my root directory:

<FilesMatch "^article$">
    ForceType application/x-httpd-php
</FilesMatch>

The result is: Accessing http://www.example.com/article/200203226 tells the server to consider article as PHP, then parse the URL, and push the content whose uniqid is 200203226 into the template. And voilà. We're done.

Conclusion

To sum up this very simple example:

  1. Call "clean" URLs when writing your code
  2. Create as many templates as needed for each type of parsing
  3. Specify their type in .htaccess

Your URLs now have a chance to be as permanent as their domain name.

For more server-side fun, you can include the same template in all the ForceType'd pages so that all the formatting will be written only once. You can also, like often in evolt.org, create longer URLs and parse them as a set of several parameter/value pairs. Be careful with that, though, because you may force search engines to index too many occurences of pages. Oh, well, maybe that's what you want after all...

Stéphane was a member of evolt.org's content working group for several years. He also belongs to Pompage.net, a French initiative dedicated to translating prominent web-related articles to French, and founded Paris-web.fr, a non-profit organising seminars about web accessibility and quality.

He has worked on the web since 1999 and is working for one of the largest phone companies in France as a client-side web expert, evangelising for accessibility and standards.

His notion of being cool involves red wine, sunglasses and <head> baseball caps. These days he's busy raising kids and pretending he manages the little devils.

I think more importantly..

Submitted by chozsun on March 30, 2002 - 14:45.

... that having query strings in your pages will prevent you from Validating 4.01.

--
ChozSun

login or register to post comments

hummmm

Submitted by jesteruk on March 31, 2002 - 18:43.

That isn't true man, many people just write query strings badly, e.g:

http://www.host.com/file.php?one&amp;two&amp;three

When you shold infact write:

http://www.host.com/file.php?one&amp;amp;two&amp;amp;three

If you put a & in a page, you must write &amp; or you will get an "unknown entity" error.

-J

login or register to post comments

for the uninitiated...

Submitted by caffiend on April 2, 2002 - 15:42.

this is the quick and easy prevention if you are using MySQL

$article_id = mysql_escape_string($expl[count($expl)-1]);

login or register to post comments

Apache's mime magic

Submitted by dholmes on April 4, 2002 - 15:47.

I've been using a little trick of (I believe) apache's mime magic module. Basically, I can call my .php files without the .php and they look like directories. It's setup in the basic apache ./configure so you may already have it.

ex. http://www.host.com/file.php/mine and www.host.com/file/mine are functionally the same thing.

Short of dups in a search engine, (one with and one without the .php) does anyone know of a problem with this that I don't know of?

login or register to post comments

Re: Apache's mime magic

Submitted by notabene on April 4, 2002 - 15:59.

dholmes,

Your solution sounds so much simpler than mine... Except that some of us (and I happen to be one of those, that's why I went so far as to try this trick) don't have access to the server's configuration.

So, yes, your trick even sounds better (I couldn't tell why but I find it sounds better --maybe because it's lower-level)... but not all of us can put it to use...

Thanks anyway, I'm sure all those who manage their onwn configuration will be happy to learn that.


login or register to post comments

no configuration needed

Submitted by tobyt on April 5, 2002 - 00:33.

Re: dholmes' suggestion

I believe this is default behaviour in Apache.

login or register to post comments

apache's default conf: yes but how...?

Submitted by notabene on April 5, 2002 - 00:53.

OK, tobyt and dholmes,

And how do you then make Apache understand that file is really file.php?

(I guess I'll have to look into the doc someday ;-))

login or register to post comments

Which way?

Submitted by MLimburg on April 5, 2002 - 04:50.

I'm interested in the ups and downs of PATH_INFO vs REQUEST_URI .... why should someone use one or the other? I've seen a few articles on this type of functionality, and they have all used REQUEST_URI ... why not PATH_INFO?

login or register to post comments

mod_rewrite

Submitted by unobserved on April 5, 2002 - 08:19.

I'm surprised you didn't mention mod_rewrite. It's a great way to overcome this problem as well as several other URL rewriting issues. The best part about mod_rewrite is that you can put it in your .htaccess file.

login or register to post comments

Re: mod_rewrite

Submitted by notabene on April 5, 2002 - 08:59.

Yes, I should have.
But I've never used it and didn't think of it.<g>

Can you suggest the right way to formulate a mod_rewrite directive that would do the same thing?

login or register to post comments

mod_rewrite example

Submitted by unobserved on April 5, 2002 - 09:13.

mod_rewrite requires a solid grasp on regular expressions for anything more complicated than this, but essentially if you were to put the following in a .htacess file and put that file in your /articles/ directory it should translate http://www.example.com/articles/200204053 into http://www.example.com/index.php?type=article&id=200204053

------
RewriteEngine on
Options +FollowSymlinks
RewriteBase /

RewriteRule ^(.*)$ /index.php?type=article&id=$1
------

The first 3 lines setup your .htaccess file to use mod_rewrite, the RewriteRule line is the only line that actually takes care of tranlating the URL. This method is not a redirect method either, it simply tells the server that when asked for a certain URL that it should provide the information from a different URL instead, the user will still see http://www.example.com/articles/200204053 in their browser window.

There's a couple of tweaks that could be made the the preceeding RewriteRule such as:
- checked for a trailing slash
- not having an actual articles directory but faking it by changing the regular expression to include articles/(.*)

But for the purpose of simplicity in example I've left those out.

login or register to post comments

Brilliant!

Submitted by notabene on April 5, 2002 - 12:10.

... bravo, I've learnt a new trick :-)

login or register to post comments

Content Negotiation

Submitted by riffola on April 5, 2002 - 20:30.

I use the following in my .htaccess to avoid using file extensions:

Options +MultiViews
DirectoryIndex index index.php index.html

This should let you use the method used in the this article without the need to use forcetype and extensionless files.

login or register to post comments

re: Content Negotiation

Submitted by unobserved on April 6, 2002 - 14:41.

riffola: The method we have been talking about are generally for dymanic content that would require command arguments to be passed to a cgi script or php / asp page ( ie: ?type=article&id=20020203 ), so that instead of having to create actual directories for each article in your database, you'd be able to link to them using 'fake' URLS (very clean, modular and extendable) instead of a real URL with a bunch of arguments ( very dirty, and hard to maintain )

login or register to post comments

Right

Submitted by riffola on April 6, 2002 - 14:46.

So you can use the following:

// get params from path_info:
list($dummy, $articledate, $articleid) = explode('/', $PATH_INFO);

Without Content Negotiation your urls would look as follows:
http://www.somesite.com/article.php/20020322/6

With Content Negotiation your urls would look as follows:
http://www.somesite.com/article/20020322/6

login or register to post comments

Nice article, but has logic flaws

Submitted by Cactus_Joe on April 8, 2002 - 02:17.

On the three points given for why to use "clean" URLs,

1) "Enables indexing by search engines" - Many search engines can and do understand parameters passed to a script.

2) "Makes for more perennial URLs" - since your data is in the database it makes no difference to perenniality, if it is cleared from the database, the clean method will also not find the error. If it stays in teh database, it stays up.

3) "Doesn't expose the server-side language" - If I wanted to hide that I can just change my web server (apache) daemon configuration (modify the AddType directive and you can call your scripts anything you like). Most servers will tell me a little of what they are capable of when I send a correctly formated HTTP request. Although there is no uniform implementation, a HEAD request will give me a good start.

Furthermore, I see a danger in using the "clean" URLs in that you are locking yourself into a limited parameter structure for the scripts. What if you need to pass more parameters for _certain_ articles at some later stage? Must one then be forced to use those parameters with junk values on all articles? I think this would make your URLs tioo long and acually detract from the placement of the article in many a search engine query.

Don't get me wrong, the article is informative and it is nice to get "clean" URLs, but the reasons given for having them are weak. use clean URLs because you like to keep it neat, not because of some grand benifit.

login or register to post comments

Another advantage ?

Submitted by Junglee on April 8, 2002 - 03:31.

I see another advantage to using clean urls which doesnt seem to have been mentioned, that of security : hiding the actual script file name from the world definitely would add some level of security.
I have seen some web based application servers prone to url hacking , for example : the domino application server from ibm is a very good example, there are quite a few documented url commands which make any domino database without the right security settings quite vulnerable, using the above mentioned method if the name of the script file could be cloaked it would go quite a way in protecting it from being url hacked...
what if tommorow some new security hole came up in php which allowed any user to execute some arbitrary commands thru the query string ? This method at least would make exploiting of that vulnerability at least a bit more difficult.
I know this sounds a bit like 'security by obscurity' and there are ways to overcome it but to me its still a valid protection mechanism...

login or register to post comments

maintenance

Submitted by unobserved on April 8, 2002 - 05:51.

You guys are side stepping the large issue of expandability and maintenance by writing off the method of 'Clean URLs' as described in this article. Unless you expect that you will never make changes to your web site or it's structure once you have launched it then you need to make plans for changes that may appear further down the road. The use of a Clean URL structure is a valuable tool in making sure your web site stays as flexible as possible down the line.

Imagine the following scenario:

Your change your article link syntax from:

http://www.example.com/index.php?type=article&id=20020418

to:

http://www.example.com/articles.php?article_id=20020418

and then a few months later to:

http://www.example.com/articles.cfm?id=20020418

If after each of these changes you had to:

a) manually (or write a script to) open all pages in the current site, and search and replace out the appropriate link code

b) test all pages to make sure all search / replace operations were performed successfully

c) ensure that any body entering new code into the site knew about the change in article link syntax, and remembered to apply it each time they linked to an article

Then you would have wasted a considerable amount of effort over the site architect that maintains a constant article syntax of /articles/20020414/ and only has the change the pointer in one file, one time, and knows that anyone entering code into the system already enters it in the 'Clean URL' format.

This issue also speaks directly to perenniality since one of the above changes in link structure will most definatly effect people (or search engines) that have the previous link stored in their database, browser bookmark, or on page link. If you were to place redirects on all the articles whose URL has changed slightly then you'd be putting just as much effort into the redirect as you would be putting into using Clean URL's in the first place.

As for the argument about more parameters being sent to the article script that simply the id of the article, please give an example of what additional parameters you might want to send as I am generally interested in other peoples test/case scenarios.

Even if it were the case the only _certain_ articles required extra parameters (a case for which I find a scenario for hard to imagine, given the fact that any additional criteria about an article of this nature should most likely be stored within the database and dealt with in the code of the application as opposed to the URL with which the article is called), there is always the last case scenario of being able to call:

http://www.example.com/articles/20020415/&param=value&param2=value

While obviously this is not a 'solid' implementation of clean URL's it speaks to the fact that additional parameters are of little to no consequence, while it is also the case that the few (the _certain_ articles that require special treatment) should not detract from the many (all of the other articles in your database)

login or register to post comments

Re: Logic flaws

Submitted by notabene on April 9, 2002 - 03:40.

(in reply to Cactus Joe's remarks)
Preamble:
- On an intranet I know they manage the whole navigation through hidden forms so that the URL is always the same, because someone's decided it's 'cleaner'. Bookmarking? They don't want to hear about it.
- Basically I wrote this article exactly for the reasons I gave, and it can certainly be disputable (for the sake of argument anything is disputable, thanks for reminding it to us, it's a matter of not being stuck in erroneous opinions), but logic flaws is a bit too strong a word for me. See just below.
- I don't care about being 'neat', by the way. So far I've done query-string based sites without any aesthetic question about the URL (which people don't look at anyway, most of the time).

Search engines: From what I gather from my server's logs, spiders tend to stop after the home page if all it features are links with parameters in them. I can send you some extracts if you like. If you have contrary information I'd be happy if you can send them, either through thelist or direct to my email. That's the primary reason that led me to rethink my strategy, URL-wise.

Perennial URLs: on purpose I addressed the case of reindexing a database. I said that in addition to classical autoincrementing you may want to use a special, unique identifier field.
When I say perennial, I don't say eternal. The day your server deletes a plain HTML file, say goodbye to the flat HTML URL all the same. What I meant is that an autoincrement, for instance, can change when you migrate a database (think for instance of deleted records). Thus if I look for article.php?uniqid=25 and when the DB is reindexed this particular article's uniqid becomes 14, how on earth am I able to find it again?

Exposing the server-side language: see unobserved's 'maintenance' answer. As I said security by obscurity doesn't protect the server for long. Swapping languages. That's a good one, unobserved, thanks to have found it for me :-)

Thanks again for your comment anyway.

login or register to post comments

search engines & parameters

Submitted by Junglee on April 9, 2002 - 03:58.

At least google doesnt seem to pickup parameterised query strings within a site , like : http://server/page?abc=x&def=y , unless a page from another website links to that particular parametrised url ...
Though using a ! (exclamation mark ) instead of a ? is in indication to search engines that the page can be indexed :
something like http://server/page!abc=x&def=y , urls like this get indexed by search engines

login or register to post comments

! vs. ?

Submitted by notabene on April 9, 2002 - 05:03.

Junglee,

I'm sure it's more a matter of "is there a '?' in the URL? Yes? OK, I won't index this" rather than "Oh, the querystring is passed through a '!' and not a '?', this guy specifies that I can index his site then".

In short: the day google sees too many query strings appended with '!' rather than '?', I'm pretty sure they'll outrule it like they did for '?'.

Hence the whole shebang.

login or register to post comments

Changing the HTTP status code on custom errordocs

Submitted by jodrell on April 10, 2002 - 07:09.

Using a custom Error document to produce clean URLs can work as long as you send a custom HTTP status response.

A typical HTTP status for a missing document will look like:

404 File Not Found HTTP/1.1
All that's required is to send something else, for example
200 OK HTTP/1.1
This will override the status set by Apache, and custom errordocuments will be indexed as normal documents.

login or register to post comments

dynamically generated dropdown menus

Submitted by redux on April 11, 2002 - 13:04.

after reading this article, i indeed proceded to make changes to some of my site's sections (still under construction, so i'll just pick an already available section). user profiles on my site are all database driven, and used to be displayed by accessing the page http://www.spiritlive.com/user_management/profile.php?user=username (e.g. http://www.spiritlive.com/user_management/profile.php?user=redux) as i have full access to apache configuration on the site, i proceeded to add some RewriteRules in the virtualhost part of httpd.conf. now all pages are accessed via http://www.spiritlive.com/user/profile/username (e.g. http://www.spiritlive.com/user/profile/redux - still not ideal, but a start). all well and good. however, at the bottom of the profile.php page i had a dropdown menu with all users in the database. this was dynamically generated, and all the surrounding form did was to call $PHP_SELF, passing on a different $user variable as a GET. this functionality obviously broke after the rewrite rule, and i wanted to avoid "breaking the spell" of clean urls by having the form just call the original url to correctly pass the $user variable (hope you're still with me...explaining it is a bit convoluted). anyway, what i came up with in the end was to turn the form into a "jumpMenu" type thing, with the values for each user entry in the select menu generated as an absolute URL http://www.spiritlive.com/user/profile/username and the form passing this on to an intermediate redirect script which only takes the variable and sends a new Header("Location: $location"). Hope this makes sense. It's still not 100% elegant, but it's getting there...

login or register to post comments

search engines

Submitted by Martin Tsachev on April 13, 2002 - 03:36.

When you say you care about search engines you should also note that the default headers send from mod_php set the expiration date somewhere in the 1970, and do not allow for proxy caching.

I don't know much about search engines but I think that may prevent your site from being indexed by some search engines, isn't it.

login or register to post comments

hmm

Submitted by tmbkr on May 18, 2002 - 12:53.

It's simply NOT true to say that Google doesn't index pages with a question mark in the URL.

login or register to post comments

google

Submitted by Martin Tsachev on May 23, 2002 - 11:19.

Yes Google indexes pages with query strings. Don't believe me try on your own.

login or register to post comments

google

Submitted by notabene on May 26, 2002 - 13:58.

I'm happy to learn that. I still don't know why spiders don't index my website, although Cactus Joe told me offsite that maybe it's because my pages are too old (they aren't even online right now, I'm redoing my site to go CMS-driven).

Thanks all who responded.

login or register to post comments

but, google likes slashes better

Submitted by nagrom on May 30, 2002 - 15:16.

google will index querystrings, but in my experience doesn't rank them as high. i have several sites that i converted to directory style querystrings (all slashes) and they have rocketed to the top of google. it also creates more opportunity to use search terms in your urls. "?id=13" or "?id=britney_spears" just aint gonna work as well for ya as /britney_spears/ will.

login or register to post comments

query strings

Submitted by Martin Tsachev on May 31, 2002 - 05:14.

I think Google for some reason may show two results from your site if you use directories and only one if you use query strings. In both cases it shows a link to more results from...

login or register to post comments

reason why it works sometimes and not others

Submitted by jrlo on July 8, 2002 - 17:59.

Haven't seen anyone mention this yet so thought i would add this from my experience today : My recently installed FreeBSD 4.6 webserver worked fine by default to display the "clean url" style pages; but a redhat7.1 box that i went to work with wouldn't. I made sure that mod_rewrite and mod_mime_magic were installed and functioning, but this still wouldn't let the clean URLs work properly -- i had to call PHP pages specfically by name in order to access them. The answer lies in Apache's "Options" section in the httpd.conf configuration file. You need to ensure that "MultiViews" is one of the options found on the "Options" line there. Or, if you don't have access to the server's configuration files, you can accomplish the same thing by using an .htaccess file in your webhost's root directory provided for your site. eg. in your .htaccess file, make sure theres a line like : Options MultiViews (you could put other Options options there as well if you wish on the same line) once this change had been made, things worked fine. for some reason on the apache 1.3x that freebsd installed, the default Options line had Multiviews present, but the redhat7.1 box didn't. And in my case, the redhat7.1 box had both httpd.conf apache configuration file to deal with, as well as a .htaccess file in the hosting directory.

login or register to post comments

MultiViews

Submitted by Martin Tsachev on July 8, 2002 - 20:12.

MultiViews have nothing to do with the script, I've used it with only FollowSymLinks.

MultiViews are used for content negotiation by Apache, see Google for example when you change your browser setting for the preferred languages (Accept-Language HTTP header) Google's language changes too.

Other things can also be negotiated, like the type of images you get, W3C uses it.

login or register to post comments

not true here apparently

Submitted by jrlo on July 8, 2002 - 20:40.

according to the apache docs (as found at : here :

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements

So, to me, if you enable MultiViews, and feed apache a URL containing abc.com/foobar and a folder foobar doesn't exist on the server (where apache could load an index from), and it does its content negotiation and decided that since foobar.php is in the root, it must be the target and uses it to display to the user, I would interpret this as allowing clean URLs as described above to function where they did not function before. I agree that having apache dance around trying to decide on the fly which files/folders found best match its content negotiation process is probably not as good as some other solution, but in my case, a) it worked, b) it was the only visible difference between the webservers configurations for the one which worked to display clean URLs and the one which didn't. I am in no way an Apache expert, but this fit the bill, and i'd love to hear fixes or other spots to check (which weren't found above)

login or register to post comments

Re: not true here apparently

Submitted by Martin Tsachev on July 8, 2002 - 20:59.

The article shows a completely different approach to clean URIs than you are using. I only meant to point some uses of MultiViews - it's Multi after all because the webserver chooses from one or more available files - the more files the better.

MultiViews is used to serve different content to different browsers, one can't handle PNG graphics then send GIFs. One user prefers French, send him French, the other English, send him English. That's the point of MultiViews.

One aspect of the uses although matches - this is the independence of the URIs from the web scripting/CGI language used to sever pages - i.e. you can change from PHP to Perl for example and still have valid links at seach engines, etc.

login or register to post comments

ForceType unsuccessful.

Submitted by entrasource on July 19, 2002 - 00:16.

The method suggested in the article makes perfect sense but its not working for me. I have a file article.php on my server, I have set up the container in my .htaccess file and urls like: www.xxx.com/article/123 are come up with Error 404. Any suggestions?

login or register to post comments

ForceType, now successful..

Submitted by entrasource on July 19, 2002 - 01:08.

I did not realize that the file had to be void of the .php extention...my mistake. Works perfect now...thanks.

login or register to post comments

Problems with this method

Submitted by Martin Tsachev on July 19, 2002 - 04:08.

Usually problems with the clean URIs arise if you are not allowed to use a .htaccess file, most other things are user mistakes.

login or register to post comments

FilesMatchis overkill

Submitted by bobokiki on August 8, 2002 - 11:29.

FilesMatch uses a regular expression match which is much more expensive than a plain string match via the Files directive.

ForceType application/x-httpd-php

This approach works, but doesn't scale very well because it requires editing the .htaccess file everytime a new script is added. An alternative is to use a directory for all your scripts:

ForceType application/x-httpd-php

But this would create URLs that look like: http://mydomain.com/myscripts/article/234324 That extra directory is annoying -- anyone know of a way to hide it somehow?

login or register to post comments

Clean URLs rocket to the top because...

Submitted by toohyper on April 4, 2003 - 08:23.

Search Engines nowadays are giving major points for words in the URL that relate to the content. For example if I had a page about how to do clean urls, http://mysite.com/CLEANURLS/blahblah will rank higher than http://mysite.com/blahblah. This said, taking the querystring off via Clean URLs and making it look like a fake directory can help (or hurt) your ranking.

login or register to post comments

Links

Submitted by zman3 on May 9, 2003 - 21:18.

If i use this then all my links includeing the ones to images on the template artical page get rewritten having /artical/ in them which makes the not work can anyone tell me why this happens and if theres a way to fix it? Thanks, ZmAn3

login or register to post comments

Link moved

Submitted by drstuey on May 10, 2003 - 16:45.

Oh, no, the link to:
Clean Up Those URLs with Apache
given by suraev above, no longer works because of the b******s at Dr Dobbs who bought webreview.com and then changed all the URLs and didn't redirect them. AAAAAAAAAAAAAAAAAAAA!!!!!

login or register to post comments

re: Links

Submitted by notabene on May 11, 2003 - 01:50.

zman3 could you post an extract of your .htaccess file?

login or register to post comments

notabene

Submitted by zman3 on May 11, 2003 - 02:51.

the only thing i have in there is the ForceType application/x-httpd-php

login or register to post comments

sorry

Submitted by zman3 on May 11, 2003 - 02:53.


    ForceType application/x-httpd-php

login or register to post comments

re: sorry

Submitted by notabene on May 11, 2003 - 03:05.

zman: re-read the article and notes. What you wrote is not a complete instruction, and I suspect tha tapache understands that as "trat any file as a PHP file"

you should specify on what file the should apply...

login or register to post comments

sorry again

Submitted by zman3 on May 11, 2003 - 04:16.

i didnt read the style guide for posting so it does not show that but i do have it ok to try again I have,

<FilesMatch "^article$">
    ForceType application/x-httpd-php
</FilesMatch>

hope that works but anyway its the exact same as this articals code.

login or register to post comments

zman: your code

Submitted by notabene on May 11, 2003 - 04:28.

Zman,

Maybe the error has to do with the code of your page. Namely, how do you write references to your images? etc

login or register to post comments

well for a basic link its just ..

Submitted by zman3 on May 11, 2003 - 04:36.


a href="main.php"


but with the brackets of course

login or register to post comments

re: well for a basic link its just ..

Submitted by notabene on May 11, 2003 - 05:29.

zman,

why not &lt;a href="/main"&gt; instead?

login or register to post comments

ok well

Submitted by zman3 on May 11, 2003 - 23:13.

well if i only had a few pages or somthing i guess i could change them but also Im using php nuke on one site and it loses its links to the theme images ect..

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.