Which characters make a URL invalid?

In general URIs as defined by RFC 3986 (see Section 2: Characters) may contain any of the following 84 characters: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;= Note that this list doesn’t state where in the URI these characters may occur. Any other character needs to be encoded with the percent-encoding (%hh). Each part of the URI has further restrictions about … Read more

Get the full URL in PHP

Have a look at $_SERVER[‘REQUEST_URI’], i.e. $actual_link = “http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”; (Note that the double quoted string syntax is perfectly correct) If you want to support both HTTP and HTTPS, you can use $actual_link = (isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] === ‘on’ ? “https” : “http”) . “://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”; Editor’s note: using this code has security implications. The client can … Read more

Absolute vs relative URLs

Should I use absolute or relative URLs? If by absolute URLs you mean URLs including scheme (e.g. http / https) and the hostname (e.g. yourdomain.com) don’t ever do that (for local resources) because it will be terrible to maintain and debug. Let’s say you have used absolute URL everywhere in your code like <img src=”http://yourdomain.com/images/example.png”>. … Read more

URL rewriting with PHP

You can essentially do this 2 ways: The .htaccess route with mod_rewrite Add a file called .htaccess in your root folder, and add something like this: RewriteEngine on RewriteRule ^/?Some-text-goes-here/([0-9]+)$ /picture.php?id=$1 This will tell Apache to enable mod_rewrite for this folder, and if it gets asked a URL matching the regular expression it rewrites it … Read more