Google Campaign & Analytics URLs with .htaccess - .htaccess

One of our clients is launching a campaign around our city and one of the requirements they want is to track from what item a visitor has scanned in a QR code. To achieve this I have entered this into my .htaccess file:
RewriteRule ^(beermat|poster|flyer)$ /video?utm_source=$1&utm_medium=PrintedMaterial&utm_campaign=VideoCampaign2012 [R=301]
So if anyone scans in the QR code that has the address: http://www.website.com/beermat it redirects to /video with the relevant attributes.
If I have the google analytics code on the /video page this should work, correct?

Try this plugin to see if google-analytics is recording anything.
This way you can see directly if it is working or not.
https://chrome.google.com/webstore/detail/jnkmfdileelhofjcijamephohjechhna

I think it would be better for you to make "poster" a directory, and the index.php inside it should set $_SESSION['found']="poster" then redirect to the main page which would read from the SESSION.
The added benefit is that you're not left with any ugly GET data, just a nice clean url, but the downside is that you have to manually create the directories, so only do this if you have a manageable amount.

Related

How to redirect a URL?

I have a problem in redirecting a URL on a Silverstripe website. I have a news feed page with a summary of articles in a paginated style. It displays 20 articles initially and switches to the next 20 based on the page number chosen. It is just the standard blog layout. When I click on page 2 then it should navigate to https://*****/news/?count=20 and for page 3 as https://*****/news/?count=40 etc. However upon clicking the blog page number it navigates to https://*****/news/news/?count=20. So the navigation link is not rewriting the parent URL.
All of my other Silverstripe websites work fine with the same blog layout except this and I don't see any reason to tweak the default code. I thought of adding a .htaccess redirect like this
Redirect 301 /news/news/?start=20 https://******/news/?start=20
but I didn't have any luck to make it work. Kindly suggest me a solution for this.
The output I expect is to redirect to the right URL
https://******/news/?start=20
Here is a simple redirection rule that should fix the symptom you describe:
RewriteEngine on
RewriteRule ^/?news/news/(.*)$ /news/$1 [R=301,L]
But I doubt that approach is a good idea. Simply because it tries to fix a symptom, not the cause. The cause is that you actually create requests to URLs that contain the /news/news/ issue which should never happen. I assume the cause of that issue is that you hand out relative references (so something like news/...) instead of absolute references (/news/...). I strongly suggest that you handle the cause instead of trying to fix the symptom.

Keep people from opening pdf directly on my webiste

I am not sure if this is possible, but I figure I would ask.
I have hundred of PDF's stored on my website, and they are all getting indexed directly by Google, so people are doing a search and the engine is taking them directly to the PDF. The issue here is that the PDF's are related to language learning and have audios that go with them. If a visitor goes directly to the PDF, then they never see the audios.
I have another page I have designed which opens up the PDF in an Iframe, and shows the audios right next to them so the users can use it.
So my question is, is it possible to redirect a user who opens:
www.mywebsite.com/something.pdf
And have it redirect them to:
www.mywebsite.com/page-with-audios/
The key here is that the pdf should still open in the IFrame on my domain.
Thanks in advance for any assistance.
If you use routing, you could make a route which has the PDF name as parameter. The route could look something like this:
/{PDF_NAME}.pdf
This could be used to match all PDF's, like example.com/foo.pdf, example.com/bar-baz.pdf. Since you then have the name of the PDF they would like to view, you can redirect them to the /page-with-audio-files with some extra data like the name of the PDF. Then you can handle opening the iFrame.
EDIT
since I now see your question was directed at .htaccess, I think the following might work too.
add this rewrite to your .htaccess:
RewriteEngine On
RewriteRule ^([a-zA-Z\-]+.pdf)$ /page-with-audio/$1 [L, R=301]
This will make the $1 variable somepdf.pdf if your request url is http://example.com/somepdf.pdf.
Then it redirects the user to http://example.com/page-with-audio/somepdf.pdf so you know which pdf was requested.

Erase '#' from url

UPDATED
I didn't understand how to make this work so I hope you know because I didn't found more solutions:
I have implemented jquery cycle in wordpress with the window.location.hash to make an individual url from each slide (example here http://jquery.malsup.com/cycle/perma.html)
Now I have an indez with some selected photos of differents categories that works with hashes like localhost/prueba/#men/#work61, localhost/prueba/#women/#work15, etc...the trick is that I have also the category /men/ and the photo #work61 permanetly cause the index may change but not the photo in the category indeed. So what I need is change the url without reloading from /#men/ to /men/ and if they share a link they will always go to the right photo and section (did I explain it well ?)
I have been testing many ways to arrive, with history.js and even with the aisle Pushestate but I didn't found the right solution. Lately I have made this with htaccess and it's closely what I need
Options +FollowSymLinks
RewriteEngine On
RewriteBase /prueba/
RewriteRule ^([^/]+)/([^/]+)/$ $1/#$2 [NE,R]
This changes me from localhost/prueba/men/work61 to localhost/prueba/men/#work61 but if I tried to add a hash to the first folder (#men), an also only work if somebody put the link directly
Any idea? Thanks in advance
I think you need to understand the URI specification, section 3.5 https://www.rfc-editor.org/rfc/rfc3986#section-3.5. Essentially, in the context of a web browser displaying HTML documents, the URI fragment (after the #) refers to a subset of the resource (page).
Basically if you removed the # from your URL, you will not be referring to a different subset of the same resource, but another resource entirely. So another page will be requested.

How to rename /page.php?1 to /welcome.html in htacces?

I have a cms that does not generate friendly url's
What is the best way to rename this without getting double content by google.
Now I have in .htacces:
RewriteEngine On
RewriteBase /
RewriteRule welcome.html page.php?1[L]
RewriteRule about-us.html page.php?2[L]
Is this the best way to do?
Any help would be appreciated
Google has no problem spidering and indexing this very simple dynamic URL scheme. But if you want extra onpage-optimization-bonus-points with the help of keyword-stuffed-URLs it would be best you switch to a CMS that creates them automatically. You save time by avoiding to maintain the link-scheme manually both in your content and the rule-file.
If not there's always the chance you forget to replace those dynamic links with your readable ones if you create new content. Also your cms will always answer both variants: the friendly one and the dynamic one, so you have to tell Google the "canonical" URL (Explanation here) to avoid duplicate content. This might happen because you can't tell how people link to content on your site.

Getting "mywebsite.org/" to resolve to "mywebsite.org/index.php"

At my work we have various web pages that, my boss feels, are being ranked lower than they should be because "mywebsite.org/category/" looks like a different URL to search engines than "mywebsite.org/category/index.php" does, even though they show the same file. I don't think it works this way but he's convinced. Maybe I'm wrong though. I have two questions:
How do i make it so that it will say "index.php" in the address bar of all subcategories?
Is this really how pagerank works?
Besides changing all the links everywhere, a simpler solution is to use a rewrite rule. Make sure it is a permanent redirect, or Google will keep using the old link (without index.php). How you do this exactly depends on your web server, but for Apache HTTPd it looks something like the example given below.
Yes. Or so I've heard. Very few people know for sure. But Google mentions this guideline (as "Be consistent"). Make sure to check out all of Google's Webmaster guidelines.
Apache config for rewrite rule:
# in the generic config
LoadModule rewrite_module modules/mod_rewrite.so
# in your virutal host
RewriteEngine On
# redirect everything that ends in a slash to the same, but with index.php added
RewriteRule ^(.*)/$ $1/index.php [R=301,L]
# or the other way around, as suggested
# RewriteRule ^(.*)/index.php$ $1/ [R=301,L]
Adding this code to the top of every page should also work:
<?php
if (substr($_SERVER['REQUEST_URI'], -1) == '/') {
$new_request_uri = $_SERVER['REQUEST_URI'].'index.php';
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$new_request_uri);
exit;
}
?>
You don't tell us if you're using straight PHP or some other framework, but for PHP, probably you just need to change all the links on your site to "mywebsite.org/category/index.php".
I think it's possible that this does affect your search engine rank. However, you would be better off using only "mywebsite.org/category" rather than adding "index.php" to each one.
Bottom line is that you need to make sure all your links in your website use one or the other. What actually gets shown in the address bar is unimportant.
A simple solution is to put in the <head> tag:
<link rel="canonical" href="http://mywebsite.org/category/" />
Then, no matter which page the search engine ends up on, it will know it is simply a different view of /category/
And for your second question--yes, it can affect your results, if Google thinks you are spamming. If it wasn't, they wouldn't have added support for rel="canonical". Although I wouldn't be surprised if they treat somedir/index.* the same as somedir/
I'm not sure if /category/ and /category/index.php are considered two urls for seo, but there is a good chance that it will effect them, one way or another. There is nothing wrong with making a quick change just to be sure.
A few thoughts:
URLs
Rather than adding /index.php, you will be better off making it so there is no index.php on any of them, since the keyword 'index' is probably not what you want.
You can make a script that will check if the URL of the current page ends in index.php and remove it, then forward to the resulting URL.
For example, on one of my sites, I require the 'www.' for my domain (www.domain.com and domain.com are considered two URLs for search purposes, though not always), so I have a script that checks each page and if there is no www., it ads it, and forwards.
if (APPLICATION_LIVE) {
if ( (strtolower($_SERVER["HTTP_HOST"]) != "www.domain.com") ) {
header("HTTP/1.1 301 Moved Permanently"); // Recognized by search engines and may count the link toward the correct URL...
header("Location: " . 'www.domain.com/'.$_SERVER["REQUEST_URI"] );
exit();
}
}
You could mode that to do what you need.
That way, if a crawler visits the wrong URL, it will be notified that it was replaced with the correct URL. If a person visits the wrong URL, they will be forwarded to the correct URL (most won't notice), and then if they copy the url from the browser to send someone or link to that page, they will end up linking to the correct url for that page.
LINKING URLS
They way other pages link to your pages is more important for seo. Make sure all your in-site links use the proper URL (without /index.php), and that if you have a 'link to this page' feature, it doesn't include the /index.php part. You can't control how everyone links to you, but you can take some control over it, like with the script in item 1.
URL ROUTING
You may also want to consider using some sort of framework or stand-alone URL rerouting scheme. It could make it so there were more keywords, etc.
See here for an example: http://docs.kohanaphp.com/general/routing
I agree with everyone who's saying to ditch the index.php. Please don't force your visitor to type index.php if not typing it could get them the same result.
You didn't say if you're on an IIS or Apache server.
IIS can be set to assume index.php is the default page so that http:// mywebsite.org/ will resolve correctly without including index.php.
I would say that if you want to include the default page and force your users to type the page name in the url, make the page name meaningful to a search engine and to your visitors.
Example:
http://mywebsite.org/teaching-web-scripting.php
is far more descriptive and beneficial for SEO rankings than just
http://mywebsite.org/index.php
Might want to take a look at robots.txt files? Not quite the best solution, but you should be able to implement something workable with them...

Resources