mod_rewrite ... please help ... I'm lost
Posted 18 November 2003 - 08:27 PM
What I\'d like to do is have:
be displayed as
I used this in my httpd.conf file:
RewriteRule /([a-z]+) /index.php?page=$1
and I was able to get it working for a little bit. I put in in the <directory> directive. I tried to put it in the .htaccess file, but it did nothing when I did. Basicaly, I have a few questions. One, how come it doesn\'t seem to work when I put it in the .htaccess file. Two, how can I write a rule that will check to see if the request actualy exists in the file system, if so, serve the actual file, not rewrite it.
Example: within the document root, there is a path \'inventory\' so
when www.mydomain.com/inventory is requested, I want to serve up the default document in the directory, not index.php?inventory. How?
Is there a good document that explains all the things used to write a rewrite rule? I\'m confused by the use of carrots and parens and brackets and what not. I read teh apache documentation, but it was not easy to understand :roll:, hence, I\'m here asking.
I read the article: http://www.phpfreaks...orials/23/0.php It wasn\'t really much help.
Also, what\'s the best place to put rewrite rules, and what <directory > options or permissions need to be on in order to use it?
lost :arrow: - Anthony
Posted 18 November 2003 - 08:35 PM
Posted 18 November 2003 - 11:11 PM
You just need to tweak your code a bit.
RewriteEngine On# Will send anyone asking for www.yoursite.com/whatever# (with or without trailing slash and regardless of case) to index.php?page=whatever# AS LONG AS \'whatever\' is not \'inventory\'. In theory, anyway.# I haven\'t tested this out yet.RewriteRule ^/([^inventory]+)/?$ index.php?page=$1 [NC]
To learn how to use mod_rewrite, you should look up regular expressions. Once you get that down, the little brackats and carots will all make sense.
Posted 19 November 2003 - 02:33 AM
This is what ended up workin for me:
RewriteRule ^(inventory/?.*) - [L]
RewriteRule ^([^.]+)$ index.php?page=$1 [L]
There might be a better way to do it, but after much trial and error, this is working.
The 1st one just checks for the inventory possability, and sends the user there. The other will run the script. This rule will also let me link to other files in the file system as long as I call them with extentions. i.e
someotherfile.php will work. not rewrite to index.php?page=someotherfile.php Took me a while to figure out how to do that. The thing that helped me the most was simple to know ot look for info on regular expression. I found htis document http://www.amk.ca/python/howto/regex/ that helped me a LOT!
One thing I couldn\'t figure out, what\'s the [L] or [NC] mean?
Thanks for your help!!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users