Jump to content

redirect issue on host (.htaccess thing probably)


Recommended Posts

Hi there,

I have a hosting/path issue:

I have a website running on, say


when I go there, processwire redirects to subdomain.maindomain.com/maindomain/,

instead of staying on subdomain.maindomain.com/

$config->urls->root is "/maindomain/" but should be just "/"

$config->paths->root is "/home/someotherdomain/public_html/maindomain/"

According to my host this is a comon problem and I recieved som instructions how to fix this for wordpress, but I can't decipher how to fix this for PW:

instructions from host:


Options + FollowSymlinks 

RewriteEngine On 
RewriteRule ^ / * (* [^ /] [^.]) $ Http (+ /.): //% {HTTP_HOST} / $ 1 $ 2 / [L, R = 301] 
- Open the database of your WordPress installation 
- Open the table 'wp_options' 
- Top Click 'Explore' 
- Adjust the following fields 'option_value' on 
- Siteurl: the url of the website 
- Home: the url of the website

I have in my config.php:

$config->httpHosts = array('subdomain.maindomain.com');

Anyone have a clue whats up with these urls?



Link to comment
Share on other sites

How does this part of your .htaccess look like?

  # OPTIONAL: Set a rewrite base if rewrites aren't working properly on your server.
  # And if your site directory starts with a "~" you will most likely have to use this.
  # -----------------------------------------------------------------------------------------------

  # RewriteBase /
  # RewriteBase /pw/
  # RewriteBase /~user/

The solution your host provided seems a little bit excessive to me. I'm not very good in reading these rules. But it seems, this is just rerouting all the subfolder requests to the actual domain. This should not be needed, if processwire does recognise the domain the right way. 

The second part of the list is totally wordpress related, as wordpress stores the url in the database, which processwire doesn't. 

Link to comment
Share on other sites


They are all commented out (like your example).

But I've tried

RewriteBase /

RewriteBase /maindomain/

RewriteBase http://subdomain.maindomain.com/maindomain/

RewriteBase /maindomain (error)

RewriteBase maindomain/ (error)

no luck so far...

But after looking around in the forum I should check that the server allows overrides (i think?)

<Directory "/">
Options All
AllowOverride All

Link to comment
Share on other sites

I'm having a similar problem with a site hosted on Bluehost and using Processwire 2.4.

The site files are under the public_html/myfolder folder and when I hit the home page in the browser I get the url as it should like: http://www.mysite.com

But when I follow a link I get the url like http://www.mysite.com/myfolder/section. So the folder name appears in the address. Not pretty. 

This is what the .htaccess looks like in the public_html folder:

Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mysite\.com$
AddHandler application/x-httpd-php54 .php
Options ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch -Indexes
RewriteCond %{REQUEST_URI} !^/myfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /myfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$ 
RewriteRule ^(/)?$ myfolder/index.php [L]
Anyone having the same issue?
Link to comment
Share on other sites

You should rewrite the url to:

$config->urls->root = '/';

Load this as early as possible in your templates, so your _init.php might be a good location. I use this all the time when storing websites in folders.

  • Like 4
Link to comment
Share on other sites


Indeed it works, but this trick seems incompatible with ProCache :/

If I do this, ProCache stops serving cached results.

But then it gets weird: With ProCache I don't need this trick! BOTH the right and wrong URL's work fine, so I guess I just have to make sure the wrong URL never gets used by string-replaceing, or something like that...

Link to comment
Share on other sites

I can't get the combo to work - maybe because my site is multilingual. 

I suppose the /nl/ or /en/ redirect happens before anything else, to the $config->urls->root = '/'; should happen just before that?

On top of my templates, might be already too late? If I put it on line 196 in index.php the url is correct, but ProCache doesn't like that..

Link to comment
Share on other sites

This site is also multilingual.

I did it like arjen suggested. Created a _init.php file in the templates folder with $config->urls->root = "/" and then I've uncommented the line (50) on config.php :

$config->prependTemplateFile = '_init.php';

That way, this code is prepended to every template and so it's executed before any code on the templates.

  • Like 3
Link to comment
Share on other sites

Hello again,

This solution isn't 100% working yet:

- an url /page redirects to /maindomain/nl/page/ instead of /nl/page/

I can see how this will give problems in the long run when the wrong url get indexed by google

- also with 404's - it still redirect to /maindomain/nl/404page/

- and also the admin is running on the wrong url  /maindomain/processwire/

It does feel a bit hacky to set $config->urls->root = '/'; I suppose the most reliable thing is to make sure the site runs in it's own webroot?


Link to comment
Share on other sites

I'm not having that problem, but of course that depends on several things.

If you can put the files on the webroot of your hosting root, I think you'll have no problems and can safely ignore the $config->urls->root  "hack".

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...