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.
Related
I have a specific folder containing ViewerJS that I want to bypass without using .htaccess
The path I want to work is /ViewerJS/#/files/viewfile/version where version is some integer.
The action viewerJS is not defined in AppController
Error: Create AppController::viewerJS() in file: src/Controller/AppController.php.
Is there any way to achieve this using CakePHP routing? I have managed to get this working before with .htaccess but would much prefer a native CakePHP way.
It's really just a way to tell CakePHP to not try to find a controller etc and just treat it as a direct link.
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.
The url structure of my cakephp based site is mysite/cakephp/myapp/index.php/controller/action/input_paramaters
I cannot remove index.php from my url, as I dont have access to httpd.conf file.
Anyways, my question is that I just need to change the url of my homepage to something like http://mysite or mysite/myapp
How would I do that?
Thanks a lot!!
The problem sounds to me that you don't have mod_rewrite enabled or Apache AllowOverwrite is not set properly.
If you don't have mod_rewrite then you cannot change the urls with the pretty ones (provided from CakePHP).
If the AllowOverwrite is not set to On. Then even if you have mod_rewrite enabled, the .htaccess files in your directories doesn't take effect.
I don't know which is worst. Speak with your hosting provider and ask for help.
It is not really clear to me which part of the URL changes. CakePHP routing applies only relative from the cake directory. So if you move from http://example.com/foo to http://www.example.org/bar nothing needs to be changed in Cake.
However you might have hardcoded some img/CSS/JS URL-s that needs some work now. I also use the HTML base tag so my app works perfectly fine under various base URL-s.
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