Archive for the ‘Scripts & Apache’ Category

Convert relative URLs to absolute (PHP code)

Once I was fixing one interesting script and came to situation when I need the code which can change relative URLs to absolute links on the HTML page.
I've got many solutions like here, i.e. regular expressions, callback functions and just foreaches with preg_matches or str_replaces.

I've checked many codes, but all of them need hours to make them do all changes that needed.
The problem is that there are many possible combinations of tag/attribute that should be modified. For example <a href=... ; <img src=... ; <form action=... ; <link href=... and others like frame/iframe, script, embed, and etc...
Read the rest of this entry »

VN:F [1.9.17_1161]
Rating: 10.0/10 (1 vote cast)
permalinkRead More CommentComments (0) CatHTML&CSS, Scripts & Apache

Simple PHP code for getting value of current URL

Today I've started making sitewide login form for WordPress based site with specific scripts.
wp-login.php uses redirect_to variable. That mean - after login user can be redirected back to the page where he was before. We must send this info to wp-login.php

So, for complete my login form I needed the value of current URL.
WP has function get_permalink(), but I needed something like this for script that is not under WP control.
And get_permalink() will cut GET request. For example if the user is on the page after login he will be redirected to

There are lots of variants of code I found. For example specific functions like this or this.
That's too huge code for me and mostly for those who uses specific ports maybe.
But all I need is just the value of the URL in user address bar!

I found pretty good code here.
It checks the URL only if it HTTP or HTTPS, and that's enough!
After little minimization I've got this:

$url = (!empty($_SERVER['HTTPS'])) ? "https://" : "http://";
VN:F [1.9.17_1161]
Rating: 5.5/10 (2 votes cast)
permalinkRead More CommentComments (0) CatScripts & Apache, Wordpress

Another .htaccess example

Working on many projects I am constantly facing the task of changing or (more often) creating .htaccess file. There is no reason to mention once again that its installment is very important for SEO purposes, but some people are not still aware of it.

At first it was like a nightmare: so many info on the Internet that I could not decide what advice to follow. .htaccess description on Apache's official site is very nice but not for optimizers - rather for tech-gurus. Then I followed the experience of other sites, and tried to implement their examples on my projects. A better result but still unsatisfied - too many variants as many people there are.

And finally I've found (I believe) the core variant accessible for all. Try to install it on your server and you must forget about 301 redirect.

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$ http://www.
nokeywordinurl/$1 [R=301,L]

- this part should redirect all non-www requests to

RewriteCond %{THE_REQUEST} ^.*/index.php?
RewriteRule ^(.*)index.php?$ http://www.$1 [R=301,L]

- and this one redirects your index.php (in my example) to . In case you have index.html - just change php to html or whatever you have.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
permalinkRead More CommentComments (0) CatScripts & Apache
CSS Template by RamblingSoul | Tomodachi theme by Theme Lab