Forum Moderators: coopster
both variables are hard coded into the link, the first being a product name and the second being the url the user is on so it would look like this
<a href="apage.php?subject=product&page=index.php">link</a>
However, I am getting a 406 error, now it works with just using the first variable so it must be something i am doing wrong with the second one. Is that the correct way to insert 2 url variables in 1 string?
Many thanks
../ (taking you back upto level 1)
and the error I get is
406 Not Acceptable
An appropriate representation of the requested resource level1/forms/index.php could not be found on this server.
<a href="apage.php?subject=variable1&page=variable">link</a>
You're not trying to pass the ampersand as the HTML special entity & are you?
Shouldn't your query string actually be
apage.php?subject=variable&page=variable
You'll definitely get an error especially if you are trying to pass certain non-alphanumeric symbols.
Why aren't you just putting the link like "yourdomain.com/folder1/folder2/folder3/index.php?product=variable? What is in that section of your website that you need to pull other than the page itself?
Are you sure you wouldn't just rather use an include statement instead of trying to pass it through the query string?
There's always a way to use mod rewrite to do most things (you should be using it anyway with dynamic URLs) so once I have an idea of what you want to achieve we can tackle it from there.
If you want to go into specifics about your site you can sticky mail me with the address.
Thanks
-Doc
Check what you are getting the the $_GET array.
echo '<pre>';
print_r($_GET);
echo '</pre>';
Then you may be able to see what is 'unacceptable' about your get array.
As it is working on one server but not on another have a look in your htaccess. As you may find that something is rewriting your rule, so what you want is getting mangled.
Also check that you are using the same version of your code on both servers.
page=../folder1/folder2/folder3/index.php
that isn't acceptable as a value, you can't have the / or . in there, apache is tying to resolve the path and it's not write so it chokes and sends you a 406
[en.wikipedia.org...]
The first is to use $HTTP_REFERER, which captures the referring page. Then you could populate the redirect (PHP or Javascript) with that information. However, $HTTP_REFERER isn't always on point, as browsers can sometimes block the referrer information depending on settings. However this is the easiest way.
I (personally) would think the best thing to do is to either:
A. Set up some kind of variable mapping to your pages (as a separate PHP file) and include that file into your pages OR
B. Set up a mod rewrite that will allow you to pass the page names as "variable-friendly" and then populate the links with those versions of the URLs.
I think if you are serious about SEO and your site you should set up a mod rewrite for your dynamic URLs so that they look static anyway. This is basic SEO 101 stuff and if you are early into the creation of your site this is recommended.
the logic of what you are doing I understand but my best answer depends on a lot more things.
you could use a cookie
you could use a session variable
you could store all of your pages/urls in a database and assign them all an id and only pass this id
you could find ways to pass only a unique part of the path and then always append index.php and send them there
there are a lot of ways to do it but you have to stay away from putting those special characters in the url
if you do sessions or cookies then you need to worry about your site still being accessible by SE spiders or what happens if the user doesn't accept cookies
if you don't already have a database then the db method could slow down the site and make a lot of work for nothing
again, we come back to the why, do they really need to go back to the page they were on? is there another option that could be as good or better?
<added>since Murdoch posted while I did
I am not sure of the SEO benefit or drawback of using GET params to only go to a form.
I don't think mod_rewrite is really a good first option as it is only a link to a single page/form, it would be better to design it so you don't need a rewrite
the included file would be good as the same as the database option but much faster. You would have to watch how much extra data you are lugging around
I don't think mod_rewrite is really a good first option as it is only a link to a single page/form, it would be better to design it so you don't need a rewrite
I just meant in general, if his site is going to be mostly dynamic URLs then he might as well set up a rewrite for them, especially if he is in the early stages.
Yes it would be a bit overdoing it to create a rewrite for just this one instance though. Just throwing ideas out there for him :)
I suppose he could write an include script that always calls for $PHP_SELF and then does a list/split with the slash as the delimiter and then put it into an array that he calls later, but that's probably unnecessarily tedious. Might as well give him all the options though.