Aliases and incorrect URLs

  htaccess, Web hosting

If you are using aliases or subdomains, it happens that the files of the web alias or subdomain are actually located elsewhere than shows URL address.

Example – web is not alias:

  • URL address: http://www.not-alias.cz/folder/file.php
  • location on your FTP: /folder/file.php

Example – web is as alias:

  • URL address: http://www.some-alias.cz/folder/file.php
  • location on your FTP: /domains/some-alias.cz/folder/file.php

In the first example URL location corresponds to a physical location. But in the second example, the URL location different from the physical location. For proper operation, it is necessary to provide a translation paths in both directions.

The translation of URL addresses -> physical location ensures our prepared .htaccess file, where are defined necessary rules. So when comes the HTTP request on URL address http://www.some-alias.cz/folder/file.php, .htaccess internally overrides this address on the http://www.some-alias.cz/domains/some-alias.cz/folder/file.php and then a request will be made. There is not usually any problem.

The translation of physical location -> URL address must take care by PHP applications .htaccess does not solve this. It concerns to which URL is inserted by PHP application to generated HTML code.

PHP and “current” URL address

PHP script must somehow be able to find out which is the URL that could properly prepare another URL links to sub-pages, etc..

Bad PHP application reading the current URL address from the variable $_SERVER[“PHP_SELF”] or $_SERVER[“SCRIPT_NAME”]. However, this is not a variable containing a URL this the variables containing information about the physical location of the currently running PHP script. From these variables you will not know the correct URL! If on your pages are generated incorrect URLs, the error is probably here.

<a href="https://kb.admin.wedos.org/domains/some-alias.cz/link/somewhere.php"></a>

The first solution to this problem is to adjust PHP application to perform the detection of the current URL in the right way from the correct variables.

This is the wrong way to check the current path:

$current_directory = dirname($_SERVER["PHP_SELF"]);

This is the correct way of using a variable $_SERVER[“REQUEST_URI”]:

$current_directory = dirname($_SERVER["REQUEST_URI"]);

Theoretically, it is enough to replace $_SERVER[“PHP_SELF”] for $_SERVER[“REQUEST_URI”]. Practically, this can be complicated depending on how is programmed your PHP application.

The second solution, which provides some content management systems, is explicit base URL addresses, which is used by CMS. PHP scripts do not attempt to detect the current URL, but it given by fixed configuration. In this knowledge base, see the appropriate procedure for the following CMS:

Notice:

In case if you will be installing on a subdomain your CMS Joomla return error “No input file specified”, then perform the following adjustment:

in file .htaccess add:

RewriteCond %{REQUEST_URI} ^/index\.php/
RewriteRule ^index.php/(.*) /$1 [R,L]

Byl pro Vás tento návod užitečný?