Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old September 21st, 2000, 04:49 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>> http://www.domain.com/somenumber/anothernumber/ the same as
>>http://www.domain.com/?page_id=somenumber&record_id=anothernumber.

You should have said /somenumber/ isn't a filesystem in the first place.

#############################################
RewriteEngine on
RewriteRule ^([^/]+)/?(.*)/$ index.php?page_id=$1&record_id=$2 [T=application/x-httpd-php]
#############################################

>>I would like this to pickup only those matches that are /somenumber/

Then add a RewriteCond above RewriteRule line:

RewriteCond %{REQUEST_URI} ^/123/(.*)$

Replace 123 with your exact number.

[This message has been edited by freebsd (edited September 21, 2000).]

Reply With Quote
  #17  
Old September 21st, 2000, 07:58 AM
forefront forefront is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 165 forefront User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 52 sec
Reputation Power: 9
If the id is (Say) 1234 and not a single digit is that OK?

Now, (spanner in works) we have an existing file ststem so people call:

oursite.com/pagetitleblah.shtml

To maintain backward compatibility, when moving to PHP-based site, each "Old" article will have a database field of "previous name" mwhich will be the previous filename minus the ".shtml" extension

How would one achieve haviung someone type in the old "static" URL, the ".shtml" being stripped off and then a PHP script pulls from a database the correct article (selecting the "old title" field")

Thanks

Reply With Quote
  #18  
Old September 21st, 2000, 09:08 AM
brian brian is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: Chalfont
Posts: 9 brian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to brian
Ok, Im almost there but I have one last nitpicky thing. I am using the following rewrite rule and it is working except for the fact that it is including the "/" in $1.

I have worked my way around this by using PHP to replace all "/" with "", but I dont feel this is the best way to do this. Is there a way to have the rewrite rule not include the "/" when rewriting the url?

############################################
RewriteCond %{REQUEST_URI} ^/[^a-z]/[^a-z]/$
RewriteRule ^(.+)/(.+)/$ /index.php?page_id=$1&record_id=$2
############################################

Here is the result from the rewrite logs:

############################################
rewrite /6/2/ -> /index.php?page_id=/6&record_id=2
############################################

See the "/" before the 6 in the above url? This is what I would like to exclude when rewriting so it doesn't need to be parsed out by PHP. Can anyone help me?

Thanks!

Reply With Quote
  #19  
Old September 21st, 2000, 10:43 AM
brian brian is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: Chalfont
Posts: 9 brian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to brian
Nevermind about that last post. Sorry :-)

Reply With Quote
  #20  
Old September 21st, 2000, 11:23 AM
forefront forefront is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 165 forefront User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 52 sec
Reputation Power: 9
This works well:

RewriteEngine on
RewriteRule ^(.+)/$ index.php?id=$1 [T=application/x-httpd-php]

And allows site.com/3/ to call index.php?id=3

But users being users, suppose they miss off the trailing slash? How can we catch:

site.com/3

Thank you

Reply With Quote
  #21  
Old September 21st, 2000, 02:39 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>suppose they miss off the trailing slash? How can we catch

RewriteEngine on
RewriteRule ^([A-Za-z0-9]+)$ $1/ [L]
RewriteRule ^(.+)/$ index.php?id=$1 [T=application/x-httpd-php]

Reply With Quote
  #22  
Old September 21st, 2000, 02:48 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>each "Old" article will have a database field of "previous
>>name" mwhich will be the previous filename minus the ".shtml" extension

RewriteEngine on
RewriteRule ^([A-Za-z0-9]+).shtml$ $1/ [L]
RewriteRule ^([A-Za-z0-9]+)$ $1/ [L]
RewriteRule ^(.+)/$ index.php?id=$1 [T=application/x-httpd-php]

Reply With Quote
  #23  
Old September 22nd, 2000, 05:29 AM
forefront forefront is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 165 forefront User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 52 sec
Reputation Power: 9
Thank you for your existing examples they are very helpful. One more before the weekend? ;-)

We want to do our whole website with one php script. Taking the example where one can type:

site.com/3
site.com/3/

and it call:

index.php?id=3

Now, if we want categories of articles so that one can type:

site.com/news/3
or any of the follwing...
site.com/news/3/
site.com/NeWs/3
site.com/NEWS/3
etc..,..

and the PHP script we would call would execute something like:

index.php?category=news?id=3

What is the all-encompassing mod_rewrite ruleset for that, case (PHP will always assume the category is lowercase)?

I would add that /news/ is not a directory (or any other named category) is not a directory, any more than /3/ is a file, just the root htdocs/ with index.php in it. All data/articles and images for these articles would store in a database.

It may be possible that we still have the odd directory that would contain physical HTML files or images, etc., SO how to exclude actual/physical directories so that the php script is NOT invoked.

Finally (another exception) the possibility must also exist that a category is not called, in which case the PHP scripts is passed a value of "home" (say)

Many thanks,

David

[This message has been edited by forefront (edited September 22, 2000).]

Reply With Quote
  #24  
Old September 22nd, 2000, 05:32 AM
forefront forefront is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 165 forefront User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 52 sec
Reputation Power: 9
[b]freebsd[b] - a business associate of mine wants some development in PHP.

If you do consultancy work please would you email me via my profile here so I can put you in touch with each other.

Thanks
David

Reply With Quote
  #25  
Old September 22nd, 2000, 01:50 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
At site.com/.htaccess:
#############################################
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([odd_dir|another_odd_dir]*)/(.*)$
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9_]+)/?$
RewriteRule ^([A-Za-z0-9_]+)/?$ index.php?home=${lc:$1} [T=application/x-httpd-php,L]

RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9_]+).shtml$
RewriteRule ^([A-Za-z0-9_]+).shtml$ index.php?page=$1 [T=application/x-httpd-php,L]

RewriteRule ^([A-Za-z0-9_]+)([^/A-Za-z0-9_]+)/?$ $1/$2/
RewriteRule ^([^/]+)/?(.*)/$ index.php?category=${lc:$1}&id=${lc:$2} [T=application/x-httpd-php,L]
#############################################

httpd.conf:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap lc int:tolower
</IfModule>

>>a business associate of mine wants some development in PHP

Sorry I don't do PHP, just Perl for programming and some UNIX stuffs.

I'll be gone for the day. See ya!

Reply With Quote
  #26  
Old October 16th, 2000, 04:30 AM
forefront forefront is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 165 forefront User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 52 sec
Reputation Power: 9
The previous rewwrite rules you (FreeBSD) gave have been very helpful. I need help with two more if you don't mind.

RULE 1:

1. Our site has some existing .shtml .html and .txt pages and three directories (images, css, data) that we will retain for total backward compatibility.

2. The new system will pass variables to a PHP script (the PHP script will explode the URL, so parameters such as "id" do not need including in the rewrite rule) The PHP script will also convert to lowercase any "MissTypEd" URLs.

3. We want one index.php page in the /htdocs/ root that will handle all client requests except those as mentioned in 1.

4. URLs will be in the format:

http://www.oursite.com/category/ OR http://www.oursite.com/category
http://www.oursite.com/category/articleid/ OR http://www.oursite.com/category/articleid

e.g.:
http://www.oursite.com/news/3/
http://www.oursite.com/views/21
http://www.oursite.com/foo/22/
http://www.oursite.com/oink/13

etc...

The CAsE of the category doesn't matter as the PHP script will convert the string to lowercase.

Finally (if this can be done with rewrite rules) we want error pages (404, 403, 401, 500, etc.,) to be called using the standard error pages the server would throw without our system.

RULE 2:
Same as rule 1 except point 2 requires mod_rerite to pass the variables to the PHP script as oursite.com/category and oursite.com/category/id which PHP will then parse.

Many thanks for your help


David

Reply With Quote
  #27  
Old November 13th, 2000, 10:12 AM
brian brian is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: Chalfont
Posts: 9 brian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to brian
I have two servers using mod_rewrite and the same exact directives, but they are rewriting two different ways. I have spent hours trying to find answers to this, but haven't had any luck.

Here is the rewrite directive that is acting wacky:

/******************************************/
RewriteCond %{REQUEST_URI} ^/tj_img/(.+)$
RewriteRule ^/tj_img/([0-9]+)/([0-9]+).(.+)$ /inc/getimage.php?page_id=$1&description_id=$2
/******************************************/

Now on one machine it is working properly and rewriting that as:

rewrite /tj_img/5/1.gif -> /inc/getimage.php?page_id=5&description_id=1

However, on another machine it is rewriting it as:

rewrite /tj_img/5/1.gif -> /inc/getimage.php?page_id=5/tj_img/5/1.gifdescription_id=1

For some reason the "&" character is being replaced by the entire URI...?

Any ideas, suggestions, or solutions about this issue would be much appreciated!


Reply With Quote
  #28  
Old November 13th, 2000, 11:05 AM
forefront forefront is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 165 forefront User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 52 sec
Reputation Power: 9
Hi

I am not expert here - hope freebsd is around! - but when I had a similar problem we found that escaping the "&" with a "&" helped.

It is clear from your comment and my own experience that mod_rewrite works differently on different O/Ss

You should also look at the other discussions on mod_rewrite and freebsd's excellent resolutions at:
http://www.devshed.com/Talk/Forums/...TML/000274.html

Hope that helps you - what O/S are you running on?

David

Reply With Quote
  #29  
Old December 19th, 2000, 07:45 AM
Heather Heather is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: Saskatoon SK, Canada
Posts: 1 Heather User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Newbie here, but this discussion of keeping arguements out of the url has helped me a great deal. For clarity I have decided to post my final understanding/solution to this problem. (it's working at one of my sites currently)

The site has a directory called documents
it has another directory called error
within documents I have the following htaccess file contents

**************************************
ErrorDocument 404 /error/error.php
DirectoryIndex index.php

RewriteEngine on
RewriteRule ^([0-9]+.html)$ index.php?id=$1
*********************************************

if you request www.domain.com/documents/1000.html

you get the contents of www.domain.com/documents/index.php?id=1000.html

if you type www.domain.com/documents/

you get the contents of www.domain.com/documents/index.php?id=

the above rewrite rule pattern matches any numeric sequence follow by a dot and then html. It isn't even aparent that php is being used in this directory so it is very search engine friendly. The php file converts the arguement to an integer so the .html part gets turfed. The php file has a default if the argument is null as well, so just typing the directory will get you the default document (or whatever you want to do with the script)

Anyway, it's exactly the solution that I came here for and what I eventually figure out from reading everything above.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > mod_rewrite help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |