Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] [OT] Creating user-friendly URLS with mod_rewrite/Apache



> So what I really want is for Apache and PHP to play nice together so
> that it will take pretty much anything after the ".com", in the above
> example where it says "kevin_cooney", and pass that to index.php to be
> used for looking up data in the database and passing the right information.
>
> But wait, there's another issue here. On my "tokyocomedy.com" web site,
> there is an actual subdirectory called "japanese", which is all about
> the Japanese side of the comedy group, and all the HTML in there is
> maintained by a different dude than me. So I'd want to make sure that
> certain exceptions will go to the right directory.
> The tricky part seems to be getting Apache to work without at least some
> kind of "category" directory. After all, without that, what would I
> specify in ".htaccess" in order to tell Apache where to take the link?

Most of the popular CMSs use something like the following snippet in an
.htaccess file (or right in the apache config). What it does is essentially say,

If the requested URI matches a real file or directory, proceed as normal.  If
not, call index.php (or whatever you set it to) which then needs to take care of
the request one way or the other (for example send 404 if it's a missing image
file)


RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php

I would use the following, which is straightforward:
RewriteEngine on
RewriteRule     ^(main.php.*)$           $1                  [L]
RewriteRule     ^([^\./]*(&.*)?)$        main.php?page=$1    [L]

put var_dump() into main.php to see what is actually passed and
experement with additional variables.

Url looks like this:

http://example.com/SomePage

adding .html at the end wouldn't make much change i think, just keep
links simple. Also if you are writing CMS or News site I would suggest
URLs in the following form:

http://example.com/283-Article_about_very_nice_linux_mailinglist.html

Search for mod_rewrite samples to get more ideas and just try one after another.

romans
http://grr.void.lv/cv


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links