Form not submitting its post parameters

Steph,

The RewriteBase is designed to UNDO a mod_alias redirection before processing mod_rewrite directives. Where are your Redirects? Get rid of silly code that is unnecessary!

Where do you set REDIRECT_STATUS? Okay, if it works, don’t fix it but if you don’t show all your .htaccess, I can’t judge. However, I know that the two methods in the tutorial work perfectly to prevent looping and the second one was designed to do exactly that (by the Apache team, i.e., preferred).

I do not know whether your code (as displayed) has any chance of working but you’re saved by Apache 2’s limit of 10 loops before it will terminate processing mod_rewrite code (Apache 1 would have to be restarted by the sysadmin!). In other words, learn the correct way and use it to avoid problems. I worked out the first (“marker”) solution before having the {IS_SUBREQ} pointed out to me so I’m NOT throwing rocks, just pointing out something learned from experience.

Regards,

DK

Hello David,

Thanks for the input. I think I need to go back to url rewriting school and sit on the bench for a while.

Stephane

Steph,

Try the tutorial article linked in my signature. Other members have found it immensely useful.

Regards,

DK

Hello David,

Thanks for the tutorial, but would you have an example of url beautifying of a simple php form ?

The trouble I have is that, after posting, the url is not beautified as the form action parameter contains the url to the php script.

<form name=‘login_form’ id=‘login_form’ action=‘$gUserUrl/login.php’ method=‘post’>

And so instead of showing /user/login/ it shows engine/modules/user/login.php after submitting the form.
Thanks

steph,

If you want to show one URI but present another to the visitor, mod_rewrite is a GREAT tool!

I’ve got to assume that user is a variable ($gUserUrl) so that makes things a little difficult, however, disregarding any/all other mod_rewrite you’re using:

RewriteRule ^([a-zA-Z]+)/login\\.php$ engine/modules/$1/login.php [L]

so you’ll have to change your action to $user/login.php.

At least that’s one way to solve that problem.

Regards,

DK

Hello David,

Thanks for the input. In fact I already have the rewrite working fine, one way.

The following works fine:

RewriteRule ^user/login/?$ engine/modules/user/login.php

When the user types in http://www.learnintouch.com/user/login/ he is taken to the form.

But the trouble is if he types in a wrong password. In such a case he then see the following http://www.learnintouch.com/engine/modules/user/login.php

That is because the form action attribute contains http://www.learnintouch.com/engine/modules/user/login.php

I attached the form and its controller.

What I would like is for the user to still see the following http://www.learnintouch.com/user/login/ when he types in a wrong password or does any mistake in the form.

I hope my issue is not boring you.

Thanks for your attention !

Hi Steph!

Okay, you’re NOT listening (reading)! Having an optional trailing / is a common problem as the visitor’s browser does not know which directory level it’s in. That doesn’t matter if ALL your supporting files are linked with absolute links but they’re usually not. Try with both the / and non-/ versions of your URI to see what I mean.

Wrong password SHOULD cause the script to reinitialize to the pseudo link, not to the actual link!

Both the form and the error handler should send to the pseudo link, too.

Not boring … helping members is why I’ve been here for so many years.

Regards,

DK

Hello David,

I should have told you before, but yes I had tried your suggestion of removing the trailing slash and question mark as in:

RewriteRule ^user/login$ engine/modules/user/login.php
RewriteRule ^engine/modules/user/login\.php$ user/login [L]

But when typing in the url http://www.learnintouch.com/engine/modules/user/login.php the browser gives a 404 Not found message.

I would like to do TWO different url rewritings. One: Typing in the user/login actually serves the content at the url engine/modules/user/login.php Two: Typing in the url engine/modules/user/login.php redirects to the url user/login so as to never display the real url (too techie, no need to tell its php, no beautiful enough, etc…)

I don’t have .htaccess files in my directories. I only have one url_rewrite.conf file that I include from my httpd.conf file.

I attached the full url_rewrite.conf file to the post.

Kind Regards,

Hello David,

The part that interested me in your tutorial was this one:

Redirect TO New Format
I have fielded questions where someone wanted to redirect their real URIs to
extensionless URIs so search engines would update to their new, extensionless format?
Okay, Apache can do that but it can not serve scripts in the new format (they have to be
redirected back to the real link!). Have I got your head spinning?
I do NOT recommend this (unless you’re on a dedicated server with low volume) as it
requires additional processing by Apache.
The key to this is the No Subrequest flag which will prevent redirection if a request has
already been redirected.

Assumes “usable link” is index.php?id=alpha

and alpha is the extensionless link

Redirect to NEW format

RewriteCond %{IS_SUBREQ} false
RewriteCond %{QUERY_STRING} id=([a-zA-Z]+)
RewriteRule ^index\.php$ %1? [R=301,L]

Redirect back to “usable link”

RewriteRule ^([a-zA-Z]+)$ index.php? id=$1 [L]

It is exactly was I was doing all along.

But my issue is how to do it on a form without loosing the posted variables by using
RewriteRule ^index\.php$ %1? [R=301,L]

Kind Regards,

Regards,

DK

Hello David,

Yes I know about the QSA flag but it only works on GET requests whereas mine is a POST one.

I also added the %{IS_SUBREQ rule as in:

RewriteRule ^user/login/?$ engine/modules/user/login.php
RewriteCond %{IS_SUBREQ} false
RewriteRule ^engine/modules/user/login\.php$ user/login/? [L]

But I still get a page not found when typing in the browser the engine/modules/user/login.php url.

Kind Regards,

RewriteEngine on

RewriteRule ^user/login$ engine/modules/user/login.php
RewriteCond %{IS_SUBREQ} false
RewriteRule ^engine/modules/user/login\\.php$ user/login [L]

Regards,

DK

But I still get a page not found when typing in the browser the engine/modules/user/login.php url.

Kind Regards,[/QUOTE]

I copied and pasted your above rules but I get the same page not found when typing in the browser the engine/modules/user/login.php url.

Steph,

Aw, $#!7! Silly error (on my part). Without R=301 (or external absolute redirection), the redirected URL will not be seen. I’m also not fond of the order so I’ve altered that, too.

RewriteEngine on
RewriteCond %{IS_SUBREQ} false
RewriteRule ^engine/modules/user/login\\.php$ user/login [R=301,L]
RewriteRule ^user/login$ engine/modules/user/login.php [L]

Sorry about that!

Regards,

DK

Hello David,

No worries at all. I’m thankful for the time you have spent already on this issue.

So I tried your last rules, but we are back to the very start of my issue.

I have the rewritten url all right, but the form parameters are not passed, meaning I cannot log in.

That is why I was telling you last week about the redirection and the loss of the form parameters on the way…

Maybe you want to try on a very simple form and see if you can pull that off ?

Thanks again !

Kind Regards,

Steph,

While I go check at Apache, please change your form action to the new URI (user/login) and see if that makes a difference.

Regards,

DK

Steph,

Have you blocked the POST method in any of your configuration files?

Regards,

DK

Steph,

Do you have any mod_alias (Redirect family) statements in your .htaccess file? If you’re not sure, please post your current .htaccess file (wrapped in a [noparse]

 ... 

[/noparse] wrapper.

Regards,

DK

Hello David,

I don’t have any .htaccess files. I only have one .user.ini file

include_path="/home/learnintouch/engine/setup"

auto_prepend_file="/home/learnintouch/www/learnintouch.com/account/setup/specific.php"

I have full control of the server and can do whatever I want in the httpd.conf file.

I just checked into it and httpd.conf is not used in it.

On an older server I used .htaccess files to preset some php variables, but now have to use this .user.ini file.

But I have never used mod_alias and don’t know what this is :slight_smile:

My problem lies only with the POST variables, they get lost.

I don’t know what you mean by blocking the POST methods, but I have not done anything that ressembles it.

Kind Regards,

steph,

No Apache configuration files at all? OMG! Are you at least using an Apache browser? If not, mod_rewrite gets emulated but that’s not always successful.

A search of Apache.org left me without anything but the above to report. However, a web-wide search brought several options as this seems to be a common problem:

  1. Do NOT redirect the form’s action, i.e. send it to the correct file. For you, that’s a problem as you don’t want the real address to be viewed.

  2. Use a mod_proxy directive in your mod_rewrite (http://stackoverflow.com/questions/358263/htaccess-is-it-possible-to-redirect-post-data). To me, that’s possibly introducing new problems (installing and configuring mod_proxy) to resolve something which shouldn’t be a problem in the first place.

  3. Do NOT use an absolute (external) redirection in your RewriteRule (you’re not).

  4. At http://stackoverflow.com/questions/358263/htaccess-is-it-possible-to-redirect-post-data, one person recommended “access[ing] $_SERVER[‘REQUEST_URI’] to see the original request.” I can’t see how this would work IF the POST array had been deleted by the redirection.

I’ll also add “do not use an absolute (external) redirection and do not create a query string.” The code I provided in post 34 above followed those rules (what happened to that code?). I suspect that the point of contention Apache has is that it usually only has to deal with POST or GET (okay, and COOKIE) within the REQUEST array.

Please let us know if any of the above work for you.

Regards,

DK