getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.59k stars 1.41k forks source link

Domain alias bug. #625

Closed jardicc closed 8 years ago

jardicc commented 8 years ago

Old and buggy (src/grav/common/uri.php) $root_path = str_replace(' ', '%20', rtrim(substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], 'index.php')), '/'));

Works good for me $root_path = str_replace(' ', '%20', rtrim(substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], 'index.php')), '/'));

Before "http://MyDomain.tld/domains/MyDomain.tld/" After "http://MyDomain.tld"

It appears one of the biggest Czech webhosting. http://kb.wedos.com/cs/webhosting/aliasy-chybne-url.html

rhukster commented 8 years ago

How about a PR?

jardicc commented 8 years ago

What is PR? I am webdesigner. Not programmer. I can't log into administration after my change.

Endogen commented 8 years ago

PR is "Pull Request" and means that you could submit a change / fix that will then most likely be accepted and added to the project

flaviocopes commented 8 years ago

The change you suggest is completely breaking Grav for me.

Does this work for you?

$root_path = str_replace(' ', '%20', rtrim(substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], 'index.php')), '/'));
jardicc commented 8 years ago

Endogen: thanks for answer. I never did pull request. I am graphic designer.

flaviocopes: yes, my change is breaking Grav. Your code doesn't works for me. Same bug as before.

This is "/www/.htaccess" in root

RewriteEngine on

# cele domeny (aliasy)
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
RewriteRule (.*) domains/%2/$1 [DPI]

# subdomeny (s nebo bez www na zacatku)
RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]

# aliasy - spravne presmerovani pri chybejicim /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]

# subdomeny - spravne presmerovani pri chybejicim /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]

ErrorDocument 404 /chyba/404/404.php
ErrorDocument 403 /chyba/403.php

# 28t.cz
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule ^([\w-]+)$ /index.php?page=$1 [L,QSA]

Grav .htaccess is located in "www/domains/MyDomain.tld/.htaccess" and has default content

jardicc commented 8 years ago

Is possible set base-url for CMS? Like Joomla or Wordpress can? http://www.joomace.net/support/docs/acesef/faq/live_site-variable-of-configurationphp

$_SERVER['PHP_SELF'] and $_SERVER['REQUEST_URI'] are not about URL... they are about physical adress on server.

rhukster commented 8 years ago

It's currently not possible to set the base url. If we discover any other situations where this would help, we'll revisit this. For now, this has not been a problem and not something we plan on addressing any time soon.