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:
  • location on your FTP: /folder/file.php

Example – web is as alias:

  • URL address:
  • location on your FTP: /domains/

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, .htaccess internally overrides this address on the 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=""></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:


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]

Děkujeme za zpětnou vazbu!