|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
post variables and mod_rewrite
Hi,
I wanted to know if anybody had any experience working with forms "method=post" and mod_rewrite? I assumed that post variables would not be handled by mod_rewrite. Is there anyway to make post variables exempt from mod_rewite? Thanks ![]() |
|
#2
|
|||
|
|||
|
>> wanted to know if anybody had any experience
Don't ask this as your question is expecting a YES/NO answer which is in no way helpful. >> Is there anyway to make post variables exempt from mod_rewite? Always tell us your exact situation with details. In doing so, it saves the resource of Devshed, time and bandwidth for everyone who is reading this thread. Your message at -> http://forums.devshed.com/showthrea...8661&forumid=15 , the first post of yours was very unhelpful and a waste of resource. Didn't I ask you to repost and be more specific already in that thread? If you post your real problem in first post, it's possible you can get an answer in the first reply, rather than waiting till 5th or 6th reply. |
|
#3
|
|||
|
|||
|
1. Environment:
Linux/PHP/Mysql/Apache/mod_rewrite running on localhost -> http://linuxbox.localhost 2. Web Site Setup: One file, index.php, which either queries a Mysql Database or, based on URL variables, includes various scripts. Example: If User requests http://linuxbox.localhost/Search PHP will include a Search Form If User requests http://linuxbox.localhost/Vegetables PHP will query MySQL database and display all Vegetables mod_rewrite is used to convert http://linuxbox.localhost/Search to -> http://linuxbox.localhost/index.php?area=Search #################################################### RewriteEngine on RewriteCond %{REQUEST_URI} ^/index.php\.php.* RewriteRule ^(.+) - [L] RewriteCond %{REQUEST_URI} ^/(.*)$ RewriteRule ^([A-Za-z0-9]+)/?([A-Za-z0-9]*)/?([A-Za-z0-9]*)$ index.php?area=$1§ion=$2&item=$3 [T=application/x-httpd-php,L] #################################################### (*Minor modification to rewrite definitions discussed in http://forums.devshed.com/showthrea...8661&forumid=15) 3. Problem/ Question: All though the mod_rewrite definitions are working. When using <form>'s with "method=post", variables seem to be missing and the script accepting the variables does not recognize the values. For Example: I use a Form to ask a user if he/she wants a Flash enabled site or plain html site: Code:
<form action="http://linuxbox.localhost" method=post>
<input type=hidden name=flash value="no">
<input type=submit value="Enter NON-Flash Site">
</form>
<form action="http://linuxbox.localhost" method=post>
<input type=hidden name=flash value="yes">
<input type=submit value="Enter Flash Site">
</form>
Because http://linubox.localhost is requested, the default page is included by PHP. This sets session variables accordingly. With mod_rewrite enabled this does not work. And the $flash variables are not processed. I have tried doing this without the RewriteEngine on. And it works. Because I have more <form>'s of this type I'm looking to make post variables immune to the effects of mod_rewrite. I searched the web and somewhere (can't find the site anymore) someone had a Javascript workaround. (But I prefer not using JavaScript) Thanks |
|
#4
|
|||
|
|||
|
>> mod_rewrite is used to convert
>>http://linuxbox.localhost/Search >> to -> http://linuxbox.localhost/index.php?area=Search Why must you use php (wasting additional resouce on top of mod_rewrite) when you can use a form with a static html page? RewriteEngine on RewriteCond %{REQUEST_URI} ^/index\.php.* RewriteRule ^(.+) - [L] RewriteCond %{REQUEST_URI} ^/Search$ # search.thml remains hidden from visitors RewriteRule ^(.+) search.html [L] RewriteCond %{REQUEST_URI} ^/(.*)$ RewriteRule ^([A-Za-z0-9]+)/?([A-Za-z0-9]*)/?([A-Za-z0-9]*)$ index.php?group=$1\§ion=$2\&category=$3 [T=application/x-httpd-php,L] On your static search.html, set: <form action="index.php" method=post> POST or GET, the $REQUEST_URI of ^/index\.php.* still match, then last as if no mod_rewrite rules present. It's all up to your index.php to interpret the POST method appropriately. Sorry I don't code php, can't help you with index.php. |
|
#5
|
|||
|
|||
|
Hi, freebsd
Thanks for your answer. Apparently post variables are not handled or distorted by mod_rewrite. The unrecognizable variables were because of bad coding of PHP! Quote:
Since I have a dynamic Top/Menu Bar and a dynamic Side/Navigation Bar (i.e. basic web site layout). I thought It would be faster having PHP do everything, but I'm always open to suggestions . I might use search.php instead of a PHP include() statement. I'll have to test the performance.BTW. Since I am using sessions... For example if the user has a cookie enabled browser, the usual URL would be: http://linuxbox.localhost/Produce/Vegetables/Carrots (as discussed in previous postings) but if the user's Browser does not accept cookies a session identifier must be appended to the end of the URL, like so: http://linuxbox.localhost/Produce/V...927bc3411123... (the session identifier is 32 alpha numeric characters long) The problem arises when somebody calls a URL like: http://linubox.localhost/Produce/66b4a42927bc3411123... now the $section variable has the session id. Since I know none of the normal variables ($group,$section or $item) are ever going to be longer than 32 character. I was thinking to check if the variable is == 32 chars long: RewriteCond %{REQUEST_URI} ^/[a-zA-z0-9]{32} then make that variable the session id else leave the regular rewrite rules. So: http://linuxbox.localhost/Produce/6...927bc3411123... -> is sent as http://linuxbox.localhost/index.php...927bc3411123... and, http://linuxbox.localhost/Produce/V...927bc3411123... -> is sent as http://linuxbox.localhost/index.php...927bc3411123... I'm not really sure how to translate "if" statements into RewriteCond /RewriteRule. Thanks again ![]() |
|
#6
|
|||
|
|||
|
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php.* RewriteRule ^(.+) - [L] RewriteCond %{REQUEST_URI} ^/.+[A-Za-z0-9]{32} RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]*)/?([A-Za-z0-9]*)/?([A-Za-z0-9]{32}) index.php?group=$1§ion=$2&category=$3&id=$4 [T=application/x-httpd-php,L] RewriteCond %{REQUEST_URI} ^/.+ RewriteRule ^([A-Za-z0-9]+)/?([A-Za-z0-9]*)/?([A-Za-z0-9]*)$ index.php?group=$1§ion=$2&category=$3 [T=application/x-httpd-php,L] This should work okay. However, there is a problem if the id is longer than 32 characters. If it's so, the 1st character of your ID will be truncated from the session and moved to the first available value. For example, a request of http://domain.com/a/b/123456789012345678901234567890123 -> group=a§ion=b&category=1&id=2345678901234567890123 That's why you need to redesign your index.php to compensate this. In fact, the cookie should be exact 32 alphanumerical characters, no more no less. If it is altered by the user then he/she just can't get the correct info and it's totally his fault for doing so, nothing harmful to your site. If the id is shorter than 32, it will be treated as the first available value. For example, http://domain.com/a/1234567890123456789012345678901 -> group=a§ion=1234567890123456789012345678901&category=&id= http://domain.com/a/b/1234567890123456789012345678901 -> group=a§ion=b&category=1234567890123456789012345678901&id= Also, try not to set cookie on top URL directory because the following will happen. For example, http://domain.com/12345678901234567890123456789012 -> group=12345678901234567890123456789012§ion=&category=&id= If you want to set cookie there, adjust the following lines (look carefully for differences): RewriteCond %{REQUEST_URI} ^/.*[A-Za-z0-9]{32} RewriteRule ^([A-Za-z0-9]*)/?([A-Za-z0-9]*)/?([A-Za-z0-9]*)/?([A-Za-z0-9]{32}) index.php?group=$1§ion=$2&category=$3&id=$4 [T=application/x-httpd-php,L] Other than these, all should work as you expected. Just try the codes and see. >> how to translate "if" statements into RewriteCond /RewriteRule As you can see from above rules, there are a total of 3 conditions: 1) IF - matches http://domain.com or http://domain.com/ , the L is to LAST it so it doesn't continue. If you have a little programming background, you should know what is last and next. 2) ELSE IF - matches when ID with 32 characters or more (due to its preceeding .+) is present 3) ELSE - matches anything non-empty As you can see, you can add more ELSE IF conditions as you wish. The more you adding, the more resource and procedure Apache have to go thru, thus slower. |
|
#7
|
|||
|
|||
|
Thanks again freebsd
|
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > post variables and mod_rewrite |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|