FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Apache mod_rewrite





dayveday
Hi all,

I'm having trouble getting the Apache mod_rewrite to work correctly on my website. Basically, I want /gallery/cake##.html to act as an alias for /gallery.php?i=## (where ## is a number). However, at the moment, it seems to be only redirecting to /gallery.php and ignoring the variables.

Here is my .htaccess file:
Code:
Options +ExecCGI +FollowSymLinks
RewriteEngine on

AddHandler cgi-script .cgi .pl
RewriteRule ^gallery/cake([0-9]*)\.html$ gallery.php?i=$1


If I request the page http://www.cakeinyourface.com/gallery/cake01.html it does not do pay any attention to the i=01 I'd hoped for. However cake01.html?i=01 does what I would expect (but obviously, not in the way I want.)

Does anyone have any experience with mod_rewrite that could help?
MrBlueSky
Try

Code:

RewriteRule ^cake([0-9]*)\.html$ gallery.php?i=$1


HTH
dayveday
Ok, I'm really confused now.

I tried what you suggested Blue, and nothing changed. Then I started trying other things I read on the web - including all the Apache documents, and nothing changed at all regardless of what I did.

In desperation, I've deleted everything from the .htaccess file which has anything to do with the RewriteEngine - but the server is still serving pages that don't exist. Rolling Eyes

Obviously, the server is still remembering when I added it for the first time (just experimenting) and isn't using the most up to date .htaccess.
Is there a way to 'reset' or 'refresh' apache to notice I've changed my .htaccess file?

Thanks
dayveday
I've done a bit more experimenting.
I have now:
Code:
Options +ExecCGI +FollowSymLinks
RewriteEngine on

AddHandler cgi-script .cgi .pl
RewriteRule ^g/cake([0-9]*)\.html$ gallery.php?i=$1]
RewriteRule ^gallery/cake([0-9]*)\.html$ gallery.php?i=$1


The first rule works like I'd expect it to
(that is www.cakeinyourface.com/g/cake01.html directs to gallery.php?i=01).
But the second rule still doesn't work! The server is still remembering some old rule which is overruling this new one! Is there a way to reset it, or do I just have to wait till the server crashes?!

HELP! Anyone?
Twisol
Just a thought - I'm a know-nothing in this department - but maybe there's some other htaccess file that's doing it? I'm thinking a bit like CSS here...
MrBlueSky
What happens if you remove this line?

Code:

RewriteRule ^g/cake([0-9]*)\.html$ gallery.php?i=$1]


(Apache doesn't need to restart for the changes to take effect)
dayveday
MrBlueSky wrote:
What happens if you remove this line?
Code:

RewriteRule ^g/cake([0-9]*)\.html$ gallery.php?i=$1]



If I remove that line, then it instantly stops working, like I'd expect it to.

Just a thought, is it because the file gallery.php actually exists in the directory I'm using? Is there a configuration which makes the server delivery the page, even if the suffix (ie. php and html) is missing? I tried this on a couple of pages I've never had RewriteRules for and it seems to work (ie. /details.html will still be served even I ask for /details)
FunDa
Hope I'm not interrupting, but I had Wordpress installed and used the mod_rewrite code that it gave to use post names in the page url. But, it it catches many(or maybe all actually) non-existent pages also (404).

Can u direct me to some tutorial learning how the rewrite works ?
Does it use another file besides the code we put in .htaccess ?
MrBlueSky
FunDa wrote:


Can u direct me to some tutorial learning how the rewrite works ?


http://www.workingwith.me.uk/articles/scripting/mod_rewrite
http://www.easymodrewrite.com/guide-syntax

Quote:

Does it use another file besides the code we put in .htaccess ?


There can be rewrite rules in Apache's global config file (I think), but you can savely assume that this isn't the case on frihost. Also rules in the same .htaccess file (or .htaccess-files in parent directories) can conflict with each other if you're not carefull.
FunDa
Thanks ... Will look them up....
Related topics
mod_rewrite
tutorials site
Seeking MySQL-php-Apache installer for WinXP
what is your php mysql apache installer package
How to install PHP and Apache in 5 min on Win98
mod_rewrite in Apache and how does it work?
.htaccess instead of mod_rewrite
only .htaccess instead of mod_rewrite
Proactively connecting Apache to the browser
problema con el mod_rewrite en wmserver 3.3
how to make old html point to php
Google Indexing .Com and .Com/index.php --> Redirect
hide folder or files in url bar
Apache mod_rewrite questions.
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.