homepage Welcome to WebmasterWorld Guest from 184.73.104.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
urlrewrite and HTML forms
can anyone help?
tongpo

5+ Year Member



 
Msg#: 4524949 posted 1:27 pm on Dec 4, 2012 (gmt 0)

I have a page that users land on. This page uses a query string that is rewritten using mod rewrite.

For example:

The user visits a page, does a search and the orginal url that a user is directed to after this search is:

www.widgets.com?widget=whitewidget&size=medium.

However this is re-written using mod rewrite to:

www.widgets.com/whitewidgets/medium

Now on the above page is a html form that redirects users back to itself and the resulting url once the form has been submitted is:

www.widgets.com/whitewidgets/medium?variable=1&variable=2

Problem is I cannot retrive the variable 1 and variable 2 values once the form has been submitted using get or post.

Im assuming this has something to to with mod rewrite and the re-written url. Can anyone help and shed some light on this please?

TIA

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4524949 posted 8:49 pm on Dec 4, 2012 (gmt 0)

However this is re-written using mod rewrite to:

"rewritten to..." is not a helpful way of saying things, because you know what you mean but we don't. I strongly suspect that you've got mod_rewrite doing the exact opposite of what you want it to do. So...

Without using the words "rewrite" or "redirect", say what happens. What, if anything, changes in the user's address bar? Where, if anywhere, does the request go?

That means:
#1 what currently happens, based on your direct experiments and looking at logs, and
#2 what do you want to have happen, if it's different.

Again: without using the words "rewrite" or "redirect". Or, ahem, anything similar.

tongpo

5+ Year Member



 
Msg#: 4524949 posted 9:51 pm on Dec 4, 2012 (gmt 0)

"rewritten to..." is not a helpful way of saying things, because you know what you mean but we don't. I strongly suspect that you've got mod_rewrite doing the exact opposite of what you want it to do. So...

Without using the words "rewrite" or "redirect", say what happens. What, if anything, changes in the user's address bar? Where, if anywhere, does the request go?

That means:
#1 what currently happens, based on your direct experiments and looking at logs, and
#2 what do you want to have happen, if it's different.

Again: without using the words "rewrite" or "redirect". Or, ahem, anything similar.


Mod rewrite is doing exactly as I want it to. Converting an url without a query string www.widgets.com/whitewidgets/medium into a query string behind the scenes. Without mod rewrite doing this the URL would be www.widgets.com?widget=whitewidget&size=medium.

Nothing changes in the users adress bar only the url if mod rewrite wasnt used would be www.widgets.com?widget=whitewidget&size=medium and not www.widgets.com/whitewidgets/medium.

So the user on the page example.php clicks a link, the link he clicks is www.widgets.com/whitewidgets/medium, this is the url that appears in the users address bar once the new page has loaded. As far as the user is concerned, nothing changes at all. It appears he has clicked a static link.

Mod rewrite is converting the static url www.widgets.com/whitewidgets/medium to a dynamic url with a query string behind the scenes. Nothing at all changes in the users address bar, as far as they are concerned it is a static link.

Ok so the user is on page www.widgets.com/whitewidgets/medium. This page contains a HTML form which submits to itself and the resulting URL in the address bar is www.widgets.com/whitewidgets/medium?widgetone=blue&widget2=red. However I cannot access the widgetone and widget2 variables for some reason. Maybe its because the static url is really a dynamic ur and the query string is being appended to a query string if you get what I mean?

[edited by: tongpo at 10:03 pm (utc) on Dec 4, 2012]

tongpo

5+ Year Member



 
Msg#: 4524949 posted 9:58 pm on Dec 4, 2012 (gmt 0)

Basically the static URL www.widgets.com/whitewidgets/medium is broken down by mod rewrite and whitewidgets and medium are interpreted as a query string behind the scenes but the URL in the address is www.widgets.com/whitewidgets/medium. Nothing changes, it appears to the user they have clicked on a static (clean) url.

Then a form on this page submits to itself and the query string is appended to the URL, the resulting URL is then www.widgets.com/whitewidgets/medium?widgetone=blue&widgettwo=red however I cannot access the variables in the query string using usual methods $_GET['widgetone'].

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4524949 posted 11:56 pm on Dec 4, 2012 (gmt 0)

Are you sure this is an apache question and not a php question?

the resulting URL is then www.widgets.com/whitewidgets/medium?widgetone=blue&widgettwo=red

:: head spinning ::

OK, so the user starts out with a short pretty URL

www.widgets.com/whitewidgets/medium

representing the "real" location

www.widgets.com?widget=whitewidget&size=medium

(OK, quasi-real, because www.example.com is in turn short for www.example.com/index.php or similar)

but then as soon as they hit the form, a new query is visibly appended to the existing rewritten URL resulting in

www.widgets.com/whitewidgets/medium?widgetone=blue&widget2=red

Where does the old query go? Does your rewrite include a [QSA] flag so it will preserve all information, whether or not the search parameters are there yet?

I see three different rewrites there and it's making me dizzy.

:: looking vaguely around for g1smd or someone like him ::

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4524949 posted 12:03 am on Dec 5, 2012 (gmt 0)

In your RewriteRule that "rewrites" you detect a friendy URL and rewrite it to a filename and parameters internally inside the server.

This rule MUST have an [L] flag to prevent mod_rewrite going off and doing other stuff with this request.

A request for
www.widgets.com/whitewidgets/medium
is already being internally rewritten to
/index.php?widget=whitewidget&size=medium
in the correct way. This is good.

In order for a request for
www.widgets.com/whitewidgets/medium?widgetone=blue&widget2=red
to be internally rewritten to
/index.php?widget=whitewidget&size=medium&widgetone=blue&widget2=red
you also need to add the [QSA] flag to ensure the originally requested parameters are re-appended to the rewritten request.

tongpo

5+ Year Member



 
Msg#: 4524949 posted 10:45 am on Dec 5, 2012 (gmt 0)

In your RewriteRule that "rewrites" you detect a friendy URL and rewrite it to a filename and parameters internally inside the server.

This rule MUST have an [L] flag to prevent mod_rewrite going off and doing other stuff with this request.

A request for
www.widgets.com/whitewidgets/medium
is already being internally rewritten to
/index.php?widget=whitewidget&size=medium
in the correct way. This is good.

In order for a request for
www.widgets.com/whitewidgets/medium?widgetone=blue&widget2=red
to be internally rewritten to
/index.php?widget=whitewidget&size=medium&widgetone=blue&widget2=red
you also need to add the [QSA] flag to ensure the originally requested parameters are re-appended to the rewritten request.


Thanks a million :). It is now working perfectly! I havent used mod rewrite much as you can probably tell. Been going round in circles for hours, onwards and upwards!

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4524949 posted 10:54 am on Dec 5, 2012 (gmt 0)

It's rare to fix a problem without seeing a single line of your code, but I've made this error far too many times in the past to let it slip past me these days.


Make sure your file has all redirects listed before any of the rewrites start.

Additionally, the rules should be listed starting with "most specific" (affects the smallest number of URL requests) to "most general" (affects the most number of URL requests). Specifically, make sure that your non-www/www canonicalisation redirect is the last of the redirects.

Make sure you do not use Redirect or RedirectMatch for any of your rules. Convert them all to use RewriteRule with the [R=301,L] flag.

For all rules that redirect, make sure the rule target includes the protocol and canonical hostname.

Make sure you escape all literal periods in patterns.

Add a blank line after every RewriteRule for human readability, and comment each block of code explaining what it should do.

tongpo

5+ Year Member



 
Msg#: 4524949 posted 1:42 am on Dec 6, 2012 (gmt 0)

Thanks for the tips :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved