.htaccess Apache Mod Rewrites (very frustrated)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I have been trying for 5 hours now to get a simple rewrite to work on the
server that hosts our website. I have been through about 20 tutorials on
this subjects without results. Here is what I am trying to do.

Our website has a URL called example:


product=1 refers to our Cedar product. I am trying to reconfigure my
.htaccess file to change to above server side to:


I have tried all sorts of combinations of code from different authors but
none work. I have contacted my hosting company and they ensure me that Mod
Rewrites work on thier Apache server. This does not work for me:

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^cedar$ /items/product.php?product=1

I have tried:

    without using the ^ * symbols
    not including the RewriteBase / command
    wrapping the code inside the <IfModule mod_rewrite.c> tags
    putting the .htaccess file inside the items folder
    removing / from in front of /items
    excluding /items
    countless other methods

Nothing works. I am hoping someone may have some insight into this. Thank
you much.


Re: .htaccess Apache Mod Rewrites (very frustrated)

Quoted text here. Click to load it

Hi Robert,
First of all, I'm not clear on what you want mapped to what. It sounds
to me like you want this:
mapped to this:

Is that correct? In that case, you've got your rewrite rule backwards.
The rule you show above attempts to map /cedar to
/items/product.php?product=1, not the other way around. Also, I don't
think that *any* URL can match this regex:

A URL will always start with a / so this would be more appropriate:

However, I'm no mod_rewrite expert and ISTR that query strings are a
little special. I don't use them on my site so I don't have any
experience involving mod_rewrite and query strings. Check the
documentation. And if you have doubts about whether or not your ISP is
telling the truth about mod_rewrite being enabled, start with a simple
rewrite rule like this one:
RewriteRule .* /foo.html [redirect=302]

That will force every URL on your site to foo.html. If that works, then
build from there.

Last but not least, the newsgroup alt.apache.configuration is probably a
better place to find help.

Good luck

http://NikitaTheSpider.com /
Whole-site HTML validation, link checking and more

Re: .htaccess Apache Mod Rewrites (very frustrated)

Robert Valcourt wrote:

Quoted text here. Click to load it

Might be a dumb question, but are you 100% sure that mod_rewrite is
installed and loaded?

If so, then the correct incantation ought to be:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^cedar$ /items/product.php?product=1 [R]

This will do a redirect rather than a transparent rewrite. Once you're
sure it's working, remove the "[R]".

Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk /
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux

Site Timeline