ModX Can't Switch Contexts - modx

I have a site that needs to be translated into three foreign languages. I created a new context through System -> Contexts, then created context settings for the base_url, site_url, and http_host. When I go to the home page in the new context, however, it routes to the File Not Found Resource from the initial context. Any ideas what I might be missing/doing wrong?
thanks
EDIT: Here are the uncommented lines in my .htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
(a lot of rewrite rules from an older version of the site that used .aspx files. None of them match with the URLs on the website)
# Add 'www' to the HTTP_HOST for all domains except seasidehotelshawaii.com
# this will also preserve the query string.
RewriteCond %{HTTP_HOST} !^(.*)[this_is_the_main_domain].com$
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I don't know a lot about .htaccess files, but this is what is in there. this_is_the_main_domain.com is the parent of three child sites. I am trying to create three contexts for each of the child sites.

You have to make some pretty extensive changes to your htaccess file. I'm guessing you didn't write a context sweitching plugin either?
Follow these tutorials:
http://www.multilingual-modx.com/blog/2011/multilingual-websites-with-modx-and-babel.html
http://www.multilingual-modx.com/blog/2011/seo-friendly-multilingual-websites-with-modx-and-babel.html
Basically, you have not given modx a method of changing context or given it a way to generate your urls correctly.

Try using the XRouting or ContextRouter plugins to route your domains to the proper context.

Related

301 redirect all root-level pages with a list of exceptions

I am in the process of migrating a website from Wordpress to a new platform (Craft CMS) and I need to set up some 301 redirects via .htaccess.
Blog posts in the old website resided in the root, I need to redirect them all to a /blog/ folder (slug is the same). Of course, because they are in the root domain there's a bunch of pages there that won't be redirected—I need to exclude these (and their sub-pages) from the redirect.
How would I do this? I tried to cobble something together using information I could glean from searching but I just end up with a redirect loop:
RewriteCond %{REQUEST_URI} !^/$ [OR]
RewriteCond %{REQUEST_URI} !^/(blog|about-bluegg-creative|what-we-do|what-we-do|doodles|contact|legal-stuff|admin) [NC]
RewriteRule (.*) blog/$1 [R=301,L]
It's probably worth mentioning that there are other redirects going on in my .htaccess so the solution needs to play nicely with those. Here's a gist of the relevant parts: https://gist.github.com/hamishtaplin/c8d5e39d4621f56038d8
You don't want that [OR] flag. What that is doing is logically or of two negative matches, which means either of those will go through since you only need to negate one or the other.
You just want:
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/(blog|about-bluegg-creative|what-we-do|what-we-do|doodles|contact|legal-stuff|admin) [NC]
RewriteRule (.*) blog/$1 [R=301,L]

htaccess, rewrite multiple pages to the same page but keep original value somewhere

I have been fiddle farting around with htaccess and RewriteEngine but I can't quite get my head around it...
I'm building a website on which I want users to be able to go to /portfolio/typography for example. But I don't want to create seperate pages for each category in this portfolio and thus I want to rewrite (redirect?) all the requests that go to /portfolio/ to the index.php of this directory and load the appropiate projects for this category from there.
Any ideas on how I could do this? I used this to redirect all the requests to /portfolio/:
RewriteCond %{REQUEST_URI} !/portfolio/$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /portfolio/ [R=302,L]
Thanks in advance,
Cas Cornelissen
EDIT
Maybe I should note that I have another .htaccess file in the root of my website.
Ok, so I found the answer to my own question...
Seems like the following is working:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1?%{QUERY_STRING} [L]

Do I need to call for .htaccess?

I have no experience with .htaccess, but I got a tip that it's very useful so I wanted to try this.
I now have a file called .htaccess, in my root folder.
The files contains this;
RewriteBase /
RewriteEngine on
RewriteCond %{HTTP_HOST} ^kellyvuijst\.nl [nc]
RewriteRule (.*) http://www.kellyvuijst.nl/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
What I'm trying to do here is create a 'www.mysite.com/portfolio/' instead of 'mysite.com/portfolio.html' I used some tutorials on this and I think it's correct, but I'm not sure.
So now I have this file, and what now? The tutorials all show what to put in the file but not what to do with it? Do I need to call for it in every .html page I have? And how do I call for it?
A .htaccess file is automatically invoked by the server.
You have just to put this into your file :
RewriteBase /
RewriteEngine on
RewriteRule www.mysite.com/portfolio/ /mysite.com/portfolio.html [L]
Hmm, you're using a lot of rules here to achieve just that.
Anyway, no you don't have to include that file. If you're hosting your site on a server with Apache it'll be included automatically. Can you also run PHP files or is your site just HTML? That's always an easy sign if you're also using Apache (not 100%, but often the go together).
If so, you could try just using these rules first:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.(.+)\.(.+)$ [nc]
RewriteRule ^(.*)$ http://www.%1.%2/$1 [R=301,L]
If that always adds www to your address, even if you type in the URL without www at least you can be certain that it works.
Then, to make the .html disappear you can add this rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule $(.*)/$ /$1.html [L]
This should make every url that ends with a slash (like portfolio/) use a .html file instead (portfolio.html), but only if /portfolio/ isn't an actual directory on your website.
(I removed your url from the rules because this way it should also work if you use it on another website, or if you change your url. It should still do what you want)
Made sure the server is configured to allow htaccess files to override host options. So in your vhost/server config, you need:
AllowOverride All

Liferay: Removing /web/ from all community sites

I can't seem to figure out how to do a url rewrite so that I can remove the /web/ from all of my community sites:
domain.com/web/communitysite1/page
domain.com/web/communitysite2/page
domain.com/web/communitysite3/page
domain.com/web/communitysite4/page
and I want it to be,
domain.com/communitysite1/page
domain.com/communitysite2/page
domain.com/communitysite3/page
domain.com/communitysite4/page
Here's a thread from Liferay, the solution there is using the virtual host; however, that's only for one of the community site for that one domain but I need the domain to be all the same for all the community sites I'm doing.
First, you will have to manualy change your pages links from domain.com/web/community... to domain.com/community
After that you need a rewrite rule to rewrite the new url to the old one without notifying users :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !^web/
RewriteRule ^(.*)$ /web/$1 [L,QSA]
Then you will need a rule to redirect users that still access the old url to the new one while changing their browser link :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} ^web/
RewriteRule ^web/(.*)$ /$1 [L,QSA,R=301]
Then you need to mix that up, BUT, if you do, you will get an infinite loop, so you need something to avoid that (a trick I use is to add an optional parameter to the first rule and check in the second one if it exists or not, if it do then you don't redirect) :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} ^web/
RewriteCond %{QUERY_STRING} !(.*&)?r=0(&.*)?$
RewriteRule ^web/(.*)$ /$1 [L,QSA,R=301]
RewriteCond %{REQUEST_FILENAME} !^web/
RewriteRule ^(.*)$ /web/$1?r=0 [L,QSA]
Thank you #Yazmat for your kind help.
#Prakash K Here's what I am currently using, it's a different solution using proxy mod.
ProxyHTMLExtended On
ProxyHTMLEnable On
SetOutputFilter INFLATE;proxy-html;DEFLATE
ProxyHTMLURLMap ^/web/(.*)$ /$1 Rli

.htaccess setting to serve multiple domains

I have two websites pointing to the same folder location. They are served via different scripts. Below is the code that I inserted in my .htaccess to make that happen. Things work fine except one problem... the domains are always served by the mentioned file, even if a resource is available - I am not able to access images, css, js folders etc.
RewriteCond %{HTTP_HOST} xyz.com
RewriteRule ^(.*)$ xyz.php [QSA,L]
RewriteCond %{HTTP_HOST} pqr.com
RewriteRule ^(.*)$ pqr.php [QSA,L]
Add these lines before your rules for domain names, e.g.:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
RewriteCond %{HTTP_HOST} =xyz.com
RewriteRule .* xyz.php [L]
RewriteCond %{HTTP_HOST} =pqr.com
RewriteRule .* pqr.php [L]
I have also made some small changes to your rules -- they will work a little bit faster:
No need for QSA flag if you are not manipulating with query string
No need for ^(.*)$ if you are not planing to capture it and use in target URL
=xyz.com searches for exact match (fast simple string comparison) while your xyz.com searches for this text in domain name using more expensive regex. Obviously, if you have some subdomains as well served by the same code (e.g. both xyz.com and www.xyz.com) then better keep what you have already.

Resources