|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
>> 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).] |
|
#17
|
|||
|
|||
|
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 |
|
#18
|
|||
|
|||
|
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! |
|
#19
|
|||
|
|||
|
Nevermind about that last post. Sorry :-)
|
|
#20
|
|||
|
|||
|
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 |
|
#21
|
|||
|
|||
|
>>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] |
|
#22
|
|||
|
|||
|
>>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] |
|
#23
|
|||
|
|||
|
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).] |
|
#24
|
|||
|
|||
|
[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 |
|
#25
|
|||
|
|||
|
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! |
|
#26
|
|||
|
|||
|
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 |
|
#27
|
|||
|
|||
|
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! |
|
#28
|
|||
|
|||
|
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 |
|
#29
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > mod_rewrite help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|