Re: [users@httpd] Mod_rewrite Newbie Questions

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

 



David--

The way you describe your problem indicates you may misunderstand what URL rewriting does.

> So I have three basic "raw" URL's that look something
> like this:
>
> http://www.geozoo.org/stacks/index.php?taxon=Animalia
> http://www.geozoo.org/kids/stacks/index.php?taxon=Animalia
> http://www.geozoo.org/topics/index.php?topic=Tundra+Mammals
>
> I want them to display like this:
>
> http://www.geozoo.org/stacks/Animalia
> http://www.geozoo.org/kids/stacks/Animalia
> http://www.geozoo.org/topics/Tundra Mammals
>

Your objective isn't to display URLS but to translate user friendly URLS (entered by your users) into program-friendly URLs (which Apache then passes to your php programs).

You want to translate
this http://www.geozoo.org/stacks/Animalia
into http://www.geozoo.org/stacks/index.php?taxon=Animalia
by using this rule:
RewriteRule ^/stacks/(.*)$  /stacks/index.php?taxon=$1 [L]

from http://www.geozoo.org/kids/stacks/Chordata
to   http://www.geozoo.org/kids/stacks/index.php?taxon=Animalia
RewriteRule ^/kids/stacks/(.*)$ /kids/stacks/index.php?taxon=$1 [L]

from http://www.geozoo.org/topics/Tundra+Mammal
to   http://www.geozoo.org/topics/index.php?topic=Tundra+Mammals
RewriteRule ^/topics/(.*)$ /topics/index.php?topic=$1 [L]

So you'll need something like this in your httpd.conf:

RewriteEngine on
RewriteLog logs/rewrite.log
RewriteLogLevel 1
RewriteRule ^/stacks/(.*)$  /stacks/index.php?taxon=$1 [L]
RewriteRule ^/kids/stacks/(.*)$ /kids/stacks/index.php?taxon=$1 [L]
RewriteRule ^/topics/(.*)$ /topics/index.php?topic=$1 [L]

Hope that helps,

John



David Blomstrom wrote:
I've bookmarked several mod_rewrite tutorials and am
currently working on one at
http://www.devarticles.com/c/a/Web-Services/Make-Dynamic-URLs-Search-Engine-Friendly/3/

I very quickly got hung up on a couple items. Before I
continue, let me give you a brief overview of what I
want to do.

You can see a page where I want to display articles
about animals at http://www.geozoo.org/stacks/

If you change the URL to http://www.geozoo.org/stacks/index.php?taxon=Animalia,
then you can click "Chordata" at the top of the column
on the right, changing the URL to
http://www.geozoo.org/stacks/index.php?taxon=Chordata.
You can continue clicking Mammalia, followed by any
order, with similar results.

I want to change this so the URL's follow this
pattern:

http://www.geozoo.org/stacks/Animalia
http://www.geozoo.org/stacks/Chordata
http://www.geozoo.org/stacks/Mammalia

There will tentatively be articles for kids at the
following rewritten URL's:

http://www.geozoo.org/kids/stacks/Animalia
http://www.geozoo.org/kids/stacks/Chordata
http://www.geozoo.org/kids/stacks/Mammalia

Another section produces raw URL's that look like
these:

http://www.geozoo.org/topics/index.php?topic=Biomes
http://www.geozoo.org/topics/index.php?topic=Tundra
http://www.geozoo.org/topics/index.php?topic=Tundra+Mammals

I want them shortened to...

http://www.geozoo.org/topics/Biomes
http://www.geozoo.org/topics/Tundra
http://www.geozoo.org/topics/Tundra+Mammal

So I have three basic "raw" URL's that look something
like this:

http://www.geozoo.org/stacks/index.php?taxon=Animalia
http://www.geozoo.org/kids/stacks/index.php?taxon=Animalia
http://www.geozoo.org/topics/index.php?topic=Tundra+Mammals

I want them to display like this:

http://www.geozoo.org/stacks/Animalia
http://www.geozoo.org/kids/stacks/Animalia
http://www.geozoo.org/topics/Tundra Mammals

* * * * * * * * * *

The tutorial directed me to visit the infamous
mod_rewrite RewriteRule Generator at
http://www.webmaster-toolkit.com/mod_rewrite-rewriterule-generator.shtml

I want to get this up and running on my computer
first, and I assume everything will automatically be
translated for the Internet when I publish my files
online. So I used
http://geozoo/stacks/index.php?taxon=Animalia as an
example of "Your Dynamic URL," then chose Directory

I entered this for Page Name:

http://geozoo/stacks/Animalia

It generated this rule:

Options +FollowSymLinks
RewriteEngine on
RewriteRule index/(.*)/(.*)/$ /stacks/index.php?$1=$2

...and said my page would be rewritten to this URL:

http://geozoo/index/taxon/Animalia/

Instead, I want it rewritten to
http://geozoo/stacks/Animalia/, which will translate
(I hope) into http://www.geozoo.org/stacks/Animalia.

But I decided to play with this for the time being. So
I created a .htaccess file and pasted the rule in it.

But when I type http://geozoo/index/taxon/Animalia/
into my browser, I get no results. So I appear to be
doing at least two things wrong.

* * * * * * * * * *

I haven't been restarting my computer at various steps
of this tutorial, because I haven't been directed to
do so. I have a str_replace function designed to
replace spaces in multi-word phrases like "Tundra
Mammals" with a +, but I'm using it on this page yet.

Do you have any idea what I'm doing wrong?

Thanks.


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
  "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux