I have never seen anything like this before and I did a search and couldn't find anything about it.
I created a site map for my site and I noticed quite a few url's were like
url.com/page1.php/page.php
url.com/page1.php/page1.php
url.com/page1.php/page2.php
Any idea of why that would be doing that? I checked all my code but I don't see anything out of the ordinary but again, I have no clue why it would do that so I am not sure what to look for.
You can use the header() method that is build in PHP. It allows you to redirect the user to specific URL.
header('Location: http://www.example.com/');
Related
I have a url, www.mysite.com/register, but when people visit this page, I'd like it to look like they're visiting www.mysite.com/shop/account/register, even though that page doesn't exist.
I'm working in PHP and JS
Thanks
EDIT:
www.mysite.com/register already exists, when a user goes to www.mysite.com/shop/account/register, I'd like it to redirect to the first url but look like they're still visiting /account/shop/register.
Ok first thing is that you will need mod_rewrite module enabled within your Apache configuration. Its a long tutorial so I recommend to read this tutorial for beginners
http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
Let's say I have a script, that redirects to another page based on your type of input.
Now that site you're redirected to already has a long query string. So what I'd like to do,
is append some html code to the end of the site without actualy sending GET or POST requests, let's say something like:
<?php
header("Location: redirectedsite.php");
//send extre html img for example
$html="<html><img scr='img.jpg'></img></html>";
?>
Is that even possible? I know about sessions and cookies, but I'd like to see if there are any alternatives.
Once the browser redirects to the other site, the body of your page gets ignored and ONLY the other site gets shown to the user.
So, unfortunately, what you want is not possible; if the redirected site is under your control you could conditionally add more contents based on a GET parameter, but it would still not work in the way you've described.
In fact, this would probably be a security nightmare if you could append HTML to any another website.
It's not possible in that manner no, sorry. If you control the destination site you could, as you say, set a session variable that would prompt the destination page to append the code, but there is no way to do it directly in the way you want. And neither option is possible if you don't control the destination.
Nope. When you do a header redirect, the browser will go there straight away. You can't add some HTML in between.
You would have to do that on the target page, or show a proper HTML page that then uses another kind of redirect (using the legacy <META> or JavaScript, or a combination of both along with a link that can be clicked manually).
Aside from appending it as a query parameter, or using session variables, you can't do this. Is there any particular reason you don't want to use sessions?
I am looking to create an SEO friendly URL after a filter has been submitted in an html form.
After playing around for a while I have found a way, however I was wondering what otehr people think of it as I'm new to development.
I have added some rewrite rules in the .htaccess file to make the urls more friendly. Examples below:
Original URL:
site-nane/list.php?brand=brand1&min-price=0&max-price=2000
URL after rewrite:
site-name/section/brand1/0-200
Currently I have the form that submits the information to a separate php page which collects the variables and creates a new url from it which then redirects with a 301. Example of php below:
$min = $_GET[‘min-price’];
$max = $_GET[‘max-price’];
$brand = $_GET[‘brand’] ;
header ('HTTP/1.1 301 Moved Permanently');
header('Location: http://site-name/section/' . $brand . '/'. $min.'-'.$max );
exit();
As you can see it collects the info and takes you back to the page and declares the previous page has permanently moved.
Questions:
Although this maybe quite primitive, will this still be ok to use without causing too much trouble?
Will google hate me for creating so many 301’s
Just noticed the code header("Location: /foo.php",TRUE,301); would it be best to use this or no difference?
Yes, I see no issues with your solution. Even if malicious user input was given it would just redirect to a non-existing page.
I don't think so. You already use the right code 301 instead of the default 302 which might cause some trouble / did create some havoc with regard to Google, stolen PR and SEO
Using header("Location:...", true, 301); is advisable. This way php could automatically make decisions based on the environment. E.g. if using an HTTP/1.0 connection php could send the 301 code with HTTP/1.0 instead of your fixed HTTP/1.1 in your solution. But still, either way is fine.
But one question: why don't you link directly to your nice URL? mod_rewrite which you are using would then already take care of assigning the parameters given with the URL to variables that you could access via $_GET as usual.
The way you've done things is a permutation of the post redirect get (PRG) pattern. In your case, it's Get redirect get.
What PRG normally means is:
User POSTs the form to a controller which does whatever you want, and build the desired url
Script REDIRECTs use to the desired url
User GETs the url, sees the result.
Generally speaking, it's a good pattern to follow, it allows you the control to - e.g. - remove default values from the resultant search url.
Regarding your specific questions
If it works, it's fine
Google won't be submitting forms, so it won't be finding the pre-processed urls to get 301-redirected unless those urls exist somewhere else already. However, you need to be linking to "http://site-name/section/brand/min-max" for any search engine to know the pages exist.
Either is fine, one line of code is easier to type though
Search engines do not submit forms.
Thus, no form action have to be friendly. (And,as another consequence - no, google won't hate you).
There is just no point in doing additional redirect instead of displaying form results.
I'm using the "Snoopy" class to pick up HTML for phrasing.
The problem is that with one of the pages I need to get the html for redirects automatically because I'm using a the sites search and if it find a perfect result it will redirect.
Here is my snoop:
if($snoopy->fetch("http://www.rottentomatoes.com/search/?search=$pagelink&sitesearch=rt")){
$printable = $snoopy->results;
If the search is exact it will place me on a page like this...
http://www.rottentomatoes.com/m/captain-america/
I need this above link.
Any help would be great,
Thanks!
From poking around in the code a little, it seems like you should be able to check the variable $snoopy->lastredirectaddr, which should be set if you got redirected (if not, it should be a blank string).
I'm new to mod_rewrite and need to do something for my client.
Suppose I have the www.mydomain.com/products.php?prod_id=32.
This product has a section (clothes) and a name (shirt). These names and sections are unique.
In a SEO-Friendly Url, it should be www.mydomain.com/products/clothes/shirt/.
I know I can create
RewriteRule ^products/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ products.php?section=$1&name=$2
I can do that, and it works. But I want people who enter www.mydomain.com/products.php?prod_id=32 to be redirected to www.mydomain.com/products/clothes/shirt/ (changed in the browser itself). How can I do that without inserting the id in my url? Is it possible to call a "pre-processing" php file in my .htaccess, and recreate "products.php?section=$1&name=$2"?
Anyone has a good link with really detailed explanation of mod_rewrite?
Thanks!
You may have a bigger problem than mod_rewrite can handle gracefully. You can also use PHP to return a redirect to the browser. That way you can access your database to figure out that product_id 32 is /clothes/shirts/
I see no other option than doing it inside PHP.
You can add something to the top of your products.php page that checks the URL ($_SERVER['REQUEST_URI']) to see if it contains products.php - If it does, redirect the person. You'll need to query your database to find out the product category and the name before redirecting though.
Remember to set the Moved Permanently header to improve SEO further :)
This data might be passed by the browser via the "Referer" header field. You could progress that url and look at the get arguments. If I remember right, this isn't supported on all browsers.
at the top of products.php (or any page you want to redirect) you could put a function call
redirectToSeoUrl();
Then in one of your include files write a redirectToSeoUrl function that gets the new url and redirects. Make sure to put the code before anything is output to the browser.
Apache? Try an .htaccess redirect. No mod_rewrite needed.
Example:
Redirect 301 /oldpage.html http://www.example.com/newpage.html