Following the advice on google's pagespeed addon, I moved my static content (images, css, javascript files) to a subdomain of my site on which there should be no cookies, thus saving some space in the request headers for each request for these files. However, on looking at the results I find that cookies are still being created for this sub domain. I have google adsense on my site and it is writing cookies to the root domain *.example.com rather than only to www.example.com
Is there any way to force adsense to write cookies only to the exact domain used for displaying the adds and not to the root domain?
There appears to be no way to force adsense to create cookies for only a specific subdomain. The generally used solution is to simply serve your content from an entirely different domain. SO uses sstatic.net, Yahoo uses yimg.com, Youtube uses ytimg.com.
I'd recommend just getting a new domain name. It's only $10 a year or so (depending on your TLD). The ROI of that is, what, 10 minutes developer time?
There can be a proxy script -- a landing page -- where all the traffic for *.example.com lands and then request is dispatched to the intended subdomain. Alternatively, you can place that script in the each subdomains' root folder to redirect the adsense cookie to wwww.yourdomain.com. In Linux environment, it can be handled using .htaccess file, like:
# place this in your subdomain's root
RewriteEngine on
RewriteCond %{HTTP_COOKIE} ^.*SOME_ID=(\d+).*$ [QSA]
RewriteRule .* ../cache/$1 [QSA,L]
Where SOME_ID is a recurring name in each generated adsense cookie. <= This is to identify/ensure that the cookie under consideration is the adsense cookie.
Related
I have a website www.example.com and it is hosted on elastic-beanstalk. I am using the name.com DNS servers. I have followed the steps in the following blogs to set up https and URL settings:
https://colintoh.com/blog/map-custom-domain-to-elastic-beanstalk-application
https://medium.com/#jbesw/tutorial-adding-https-to-a-custom-domain-on-elastic-beanstalk-29a5617b8842
i.e
Create a CNAME pointing www.example.com to the beanstalk
Add a URL redirect for #.example.com to https://www.example.com
After this, the links www.example.com works, and http://example.com gets redirected to www.example.com.
But for a page inside the site, like www.example.com/about, just typing in http://example.com/about does not work and does not get redirected to www.example.com/about.
Most blogs suggest moving to AWS Route 53. Is that the only option?
The issue, as you've found out, is that DNS-level redirects don't work on a page-specific level. At least, not without some extra magic happening in the background (which some registrars implement.)
Even if that setup did work, you'd still have some SEO issues to deal with. For example, you want the example.com > www.example.com redirect to (In any case I know of) to be a 301 redirect. This let's search engines like Google know "Use only the www version of this page please." Otherwise, you effectively have two pages floating around out there either of which (or both) could be indexed and considered duplicate content of one another.
Using the Route 53 servers is certainly an option but no one you have to use. The issue is that you need to do this on a server-level—not a DNS level.
On a server level, you can specify more complex and granular redirection rules such as "send any non-www, non-https traffic to the www, https version of the page and indicate this is a permanent preference (301)` that redirect (on an Apache server) would look like this:
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Quick Reference: NC means case-insensitive matching. R specifies the type of redirect (301 here), NE specifies to not escape characters like # or ? which are used in many URL schemes. For a full list of flags used during Apache RewriteRules, read this webpage.
There are different ways to achieve this for Apache, NGINX, and Windows Server. Amazon has a reference article detailing some of the implementation approaches for this. Copying the details of the article here is beyond the scope of your question IMO.
So, to answer your question: Route 53 isn't your only option. You can absolutely use whatever registrar or DNS host you'd like. The issue is that you need to re-think your approach entirely and focus on server-level rules rather than DNS-level rules. I'm no expert and find it annoying to do it this way, so hopefully, someone will jump in with a more insightful approach.
I have been unpublishing old pages on my website. To avoid 404 pages, I'd like to redirect these pages to a generic page.
So for example this page:
https://www.portal-gestao.com/artigos/7380-7-t%C3%A1cticas-de-sobreviv%C3%AAncia-%C3%A0-crise-nas-vendas.html
Should redirect to:
https://www.portal-gestao.com/artigos/
I'm not very skilled with .htaccess or regular expressions, I've bee trying to redirect the pages with:
RewriteRule ^artigos/(.*)$ /artigos/$1 [R=301,L]
But something isn't working, can anyone help?
Late information... the site uses a Joomla CMS. See the UPDATE below.
To redirect requests for physical files that no longer exist you need to actually check that the file no longer exists, otherwise it will indeed "redirect everything" (as mentioned in comments).
For example, to redirect any requests of the form /artigos/<something>, that do not map to physical files, to /artigos/ you can do the following:
RewriteEngine On
REwriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(artigos/). /$1 [R=302,L]
The $1 backreference simply prevents you having to repeat the directory name.
The first condition that checks against the REDIRECT_STATUS environment is intended to ensure that only direct requests are redirected. This is probably only required if you are still on Apache 2.2 (as opposed to 2.4) since mod_dir will execute first, rewriting the redirected request to index.php (if it exists) and causing a rewrite loop. On Apache 2.4, mod_dir executes later.
Test with a 302 and only change to a 301 when you are sure it's working OK - to prevent caching issues.
You will need to clear your browser cache before testing.
However, a 404 would generally be a better response. The search engines will likely see the redirect to a common root as a soft-404 and users are more likely to be "confused" when they don't see the information they requested.
RewriteRule ^artigos/(.*)$ /artigos/$1 [R=301,L]
By itself, this would result in a redirect loop, as it simply redirects to itself.
UPDATE: it's not a file, it is an article in a Joomla CMS
If valid URLs do not map to physical files then you can't do this in .htaccess. In your case, a valid URL is determined by the Joomla CMS (as stored in the Joomla database). .htaccess is processed at the very start of the request, before control passes to PHP/Joomla. Directives in .htaccess can only look at the HTTP request and the physical filesystem.
Joomla uses a front-controller pattern. All URLs, that do not map to physical files (to exclude static resources like CSS, JS and images), are internally rewritten to index.php (the "front-controller"), this effectively "routes" the URL and decides what content should be returned.
What you are asking could only be done on a static website where URLs map to physical files on the file system.
You need to perform this redirect in Joomla itself, when Joomla has determined that the requested URL does not exist. (This is actually more efficient anyway as you only need to execute your code after a 404 has been determined, rather than on every single request, as it would be if you used .htaccess.)
I've been working with my .htaccess file and mod_rewrite for a couple of days now trying to create a rule that allows people to point their own domains to paths of my website.
i.e. they have created a landing page on my website, located at www.website.com/landingPages/myUniqueWebsite
and they would like to point their domain, www.myuniquewebsite.com to that url above.
Could anyone suggest what apache rule to use to accomplish this?
My .htaccess currently looks like this:
# disallow access to any directories without an index file
Options -Indexes
RewriteEngine on
# remove trailing slash
RewriteRule ^(.*)/$ /myProject/$1 [L,R=301]
FallbackResource ../appContent/BasePage.php
Where the BasePage above takes the directory data from the URL and gets the users landing page data from the db.
Also should they be using domain pointing or aliasing in their hosting provider dashboard?
I'm having trouble with a 301 redirect. I've tried a few but they are not working as I need it.
I have an old website that no longer exists, I would like to forward the entire domain to a landing page on my new website.
So when someone types in www.olddomain.com I want them to go to www.newdomain.com/landingpage.php
The problem is that I want ALL requests on the old domain to go to that landing page. Currently I have the domain forwarded thru GoDaddy, and when someone (or Google) types in www.olddomain.com/whateverpage.htm or forwards it to www.newdomain.com/landingpage.php/whateverpage.htm
This is causing issues with Google indexing.
So I need a redirect that will send ALL requests of ANY page at www.olddomain.com/ to www.newdomain.com/landingpage.php
What should I use?
You can use this rule on DocumentRoot of old site:
RewriteEngine On
RewriteRule ^ http://newdomain.com/landingpage.php? [R=301,L]
Assuming you're using a LAMP stack (linux server, MySQL, PHP) you can use rewrite rules in an .htaccess file to capture all requests to www.newdomain.com/landingpage.php* and redirect them back to landingpage.php. If you're hosting on a Windows server, you can do these sort of redirect rules with the URL Rewrite module in IIS (which can import .htaccess rules).
I have updated my website to now use the codeigniter framework my new urls are like the following example.com/index.php/home/page/page-title
The old urls are example.com/index.php?option=com_content&view=article&id=249
Ideally I want to do a redirect for all links formatted in the old way to the new links but there are a lot of pages on the website and the titles/id do not match.
I do not want to write an individual rule for every page. eg
Redirect 301 /oldpage.html http://www.example.com/newpage.html
I do not mind having all the wrongly formated urls be redirected to the home page/404 page if this easier.
I can see this requires a more complicated rule that uses regex something I have never been very good at.
Any help appreciated
Thanks
The server doesn't know which ID may match a given title. You will have to handle these cases in CodeIgniter. Build a table with all old IDs and new URIs. Write a script that handles these requests and does the redirect.
Example (I haven't touched CI recently):
.htaccess
# parameter 'id' followed by a '=' followed by a number
RewriteCond %{QUERY_STRING} id=(\d+)
RewriteRule ^ /redirector/url/%1? [L,R=301]
CodeIgniter
Redirector could be a CI class, that looks into url, validates it as a positive integer, searches the database for a matching new URI and sends a Location header.
Try the RewriteMap directive. See http://httpd.apache.org/docs/2.0/misc/rewriteguide.html for details.