I have been researching like crazy trying to find a way to make my backbone application seo friendly. Ideally, I would like to use https://github.com/thomasdavis/seoserver which should be a no hassle setup, but there is a problem.
All of these solutions use a rewrite rule requiring a hashed url:
RewriteCond %{QUERY_STRING} ^escaped_fragment=(.)$
RewriteRule (.) http://address-of-seoserver:3000/%1? [P]
And I'm using HTML5 Push State URL in my backbone app. Is there some way to tell google to redirect only the application pages without a hashed url?
First since you won't have a hash you will have to tell google that you are trying to load ajax content.
Make sure the following is in your head tag for all of the pages that won't have a hash
<meta name="fragment" content="!">
You can then use the follow rewrite rule for google bots.
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
RewriteRule (.*) http://%{HTTP_HOST}:3000%{REQUEST_URI}? [P]
Related
I'm facing url (hash) redirecting issue in my angular application. I tried fixing it with angular way but it doesn't work so I go with custom .htaccess way. This solution is working fine but I'm facing issue with (duplicate) URL(s) which have hyphen(s). Example below.
.htaccess
RewriteEngine On
RedirectMatch 301 ^/terms http://example.com/#terms
RedirectMatch 301 ^/terms-bb http://example.com/#terms-bb
As per above example if open "http://example.com/terms-bb" it redirects to "/terms" instead. So is there any way that I can strictly match these duplicate urls?
You only anchored your patterns at the start there, so ^/terms matches on anything that starts with /terms.
If you want a strict match, then anchor it at the end as well – ^/terms$.
I'm pretty new with AngularJS and server config stuff, and this is a problem I haven't found a satisfactory solution so far.
I would like to be able to use the HTML5 url on a website (without hashbangs), so that I could use addresses like "mydomain/contact" to navigate (I'll stick with the "contact" example for simplicity).
To do that, as I've found so far, one should do two things:
Enable HTML5 on the client side
Enable the HTML5 format on the app/app.js file (also adding the dependency)
$locationProvider.html5Mode(true);
It makes possible to click on links and get the proper url. Still, it doesn't allow someone to access directly the HTML5 url. To get to the "contact" page, I still can't directly access "mydomain/contact" (we get a 404) and I know it makes sense. To solve this, it is still necessary to implement something server-side.
Server-side config
Configure the server to respond with the right file, i.e., I should configure the server to make it respond the same way when I request "mydomain/#/contact" and "mydomain/contact".
The last item is where I'm stuck. I've found many answers like this: "you should configure your server" (they assume the reader already knows how to do this. I don't), but I can't find a complete example on how to do that or where to put any needed files.
I'm using AngularJS 1.6.x and npm 3.10.9 (npm start). My question is: is there any complete example on how to fully use HTML5 urls with AngularJS?
The only problem that exists is that angular can't handle requests it doesn't receive. You need some catch-all so that all routes (/contact etc) are passed to your main index-file.
When you say .htaccess I assume apache. Even so I'd still put nginx in front of apache since it's lightweight and easy to configure (at least compared to the apache behemoth). Sorry, I know that is a very opinionated answer. Anyway with nginx the entire config could look like this:
# usually this file goes in /etc/nginx/conf.d/anyfilename.conf
# but it might vary with os/distro.
server {
listen 80
root /var/www/myapp;
location / {
try_files $uri $uri/ index.html;
}
# And if you want to pass some route to apache:
location /apache {
proxy_pass http://127.0.0.1:81; # Apache listening on port 81.
}
}
I'm sure the same can be achieved with apache alone, but I couldn't tell you how. But perhaps this can be of help: htaccess redirect for Angular routes
There are so many silly toolpacks and utilities I've wasted time learning in my life, but nginx is the one tool I'll never regret I picked up.
I developed a Single Page App with AngularJS and I try to deal with SEO troubles. I use html5 to design my URL's with this configuration :
$locationProvider.html5Mode(true);
With this conf, the refresh will not work because the browser will looking for the page on the server, which doesn't exist. So I added that in my .htaccess which works perfectly:
RewriteRule ^(.*) www/index.html [L]
And here comes the trouble when I try to improve my SEO via Google Webmaster Tool. With Fetch as google, it works great ! But when I use Data Highlighter to add some ratings, description, nothing work. I explain, something is loaded but it's only the home page (the default route defined in my app.js).
Does Fetch as Google work the same way as Data Highlighter ?
Data Highlighter accepts to deal with pages wich are indexed only, does that mean all my pages which are indexed look like my home page ?
To top it all, I have only 1 page indexed in the Index Status sub-menu, is it normal whereas I added 20 url's in my sitemap.xml ?
I have installed Drupal7 in a subdir http://foo.com/site, and I want to keep it there.
However, I would like urls like http://foo.com/node/101 to be available as well as http://foo.com/site/node/101. The latter would stay the canonical url.
I was hoping I could just move index.php up and modify some things, much like wordpress. But I cant find detailed instructions anywhere. Does anyone know ?
You should never move index.php outside of the Drupal folder or hack into the Drupal core. This would get you a maintenance hell whenever you'll need to update your Drupal core.
Instead, you can use URL rewrite to create redirects (HTTP 301, permanent). Assuming you're running Apache, you can use mod_rewrite and create a .htaccess file in the server's document root with rewrite rules in it. For example:
RewriteEngine on
RewriteRule ^node/(.*)$ site/node/$1 [R=301,L]
You can modify the rewrite rule, or add new ones for additional matched to redirect.
I am getting ready to deploy a cakephp app onto the web and i want to move all the assets (img, js, css) to a CDN to increase performance. Is there a way to globally change the location the HTML helper links to assets instead of having to change every link.
Recently I came across this cool helper that accomplishes this task with relative ease. It's called Asset Host Helper and can be obtained from its GitHub repository.
What I liked best about it is that you don't need to worry about changing the location of the assets in your development copy (most likely on localhost) or in your production copy (on the CDN). The helper takes care of it automatically.
Check it out - this might just be the tool you're looking for.
Cheers,
m^e
If the routes and filenames persist, maybe mod_rewrite might be less painful.
RewriteCond %{REQUEST_URI} ^/css/
RewriteRule ^css/(.*)$ http://cd.yourdomain.com/css/$1 [R=301,L]
I had a similar problem, here's how I solved it:
Adding a prefix to every URL in CakePHP
The AppHelper::url() method is the place you should be interested in.
I have a solution but it involves changing the core, I know I know...I have already slapped myself for doing it ;-)
We had a project that was built and then needed a CDN so we just added a bit of code to the HTML and Javascript helpers to assist us.
In the /cake/libs/view/helpers/html.php file add this at line 360
if (Configure::read('Asset.CDN.enabled')) {
$static_servers = Configure::read('Asset.CDN.static_servers');
if(sizeof($static_servers) > 0) {
shuffle($static_servers);
$url = $static_servers[0].$url;
}
}
and in /cake/libs/view/helpers/javascript.php ass this at line 288
if (Configure::read('Asset.CDN.enabled')) {
$static_servers = Configure::read('Asset.CDN.static_servers');
if(sizeof($static_servers) > 0) {
shuffle($static_servers);
$url = $static_servers[0].$url;
}
}
Then in your app/config.core.php file just add the following configuration options
// Static File Serving on a CDN
Configure::write('Asset.CDN.enabled', false);
Configure::write('Asset.CDN.static_servers', array('http://static0.yoursite.com.au/', 'http://static1.yoursite.com.au/'));
Now when you refresh your page each file that is outputted through the html/javascript helper will automatically pick a random static server.
Note that unless you are using absolute paths (including domain names) in your css files you will need to make sure the images are also on the static server.
I know you shouldn't really play around in the core but sometimes it is really just easier.
Cheers,
Dean
I know this is an old question but in case any future people stumble across it in rails 3.1 you can now use
config.action_controller.asset_host = "ATBTracking"
in config/environments/production