Archive for March 2008
mod_rewrite loaded but not working
There are lot many tutorials on the Net about mod_rewrite module of Apache web server. You follow those tutorials and get nowhere (OK, at least I couldn’t for the most of time until I found http://ubuntuforums.org/showthread.php?t=645282).
This post particularly deals with Apache 2.0 series. I am afraid if this material is applicable to Apache1.3 series of server, however, you can try yourself if it works for you.
Make sure that mod_rewrite is loaded. This can be done by checking PHP settings. Put <?php phpinfo(); ?> this code into a PHP file and browse this using a browser. It will display PHP info along with loaded modules in Apache. Search this page for string “mod_rewrite”. If you can find this, it means that the module is loaded and you can skip the rest of this paragraph. Still here, most likely you have not mod_rewrite loaded, yes? Under Ubuntu Linux (in other distros also, I think) you can load this module using sudo a2enmod rewrite command in the terminal window.
For Linux
The httpd.conf file is not used in Apache2; the new configuration file is apache2.conf. On my installation, the httpd.conf was just empty (zero byte file size). All installation wide configuration of Apache2 can be done through apache2.conf file making httpd.conf redundant.
Many of the tutorials I came across point out that we have to change “AllowOverride None” to “AllowOverride All”, but unfortunately failed to pin point where exactly this setting is to be changed. Of course, the problem I had was with this setting only. (I am next to sure that you also have problem with this setting only.) Locate the file: /etc/apache2/sites-enabled/000-default. Search for the section
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</Directory>
Now change “AllowOverride None” to “AllowOverride All”. Force restart the server using sudo /etc/init.d/apache2 force-restart and you are done.
For Windows
The Apache2 configuration file under windows is httpd.conf. Look for the line
#LoadModule rewrite_module modules/mod_rewrite.so
in the httpd.conf file. Remove the leading # comment sign to enable the server to load the module. Next, search for
<Directory "${path}/www">
:
AllowOverride None
:
</Directory>
section. Here you will find AllowOverride None line. Change it to AllowOverride All so that the setting in .htaccess file can be used by the server (otherwise, the server doesn’t process whatever is there in .htaccess file).
Of course you’ll need to restart the server for the things to work. I hope this will be helpful.
Splitting a unicode string into individual characters in PHP
I had a hard time finding something that can easily split a unicode string into individual unicode characters. Finally, I find something here http://bugs.php.net/bug.php?id=27103 that gave a straightforward method to do the splitting. Here is the code:
$s = "यहां पर एक युनिकोड लड़ी (string) डालें";
print "<pre>";
print_r( preg_split("//u", $s, -1, PREG_SPLIT_NO_EMPTY));
print "</pre>";
The above code will output the individual letters in the string $s. Feel free to adapt to it your needs. Cheers!
Scripts on WordPress
Today I tried to put my javascript code into a post on WordPress. To my dismay, it simply did not work on it. Moreover, to my surprise it is found that WordPress strips all the <script> tags and leaves almost nothing behind. Whatever was left was of no avail. Anyway, if you need to translate Polish words into English, you can search the ‘Pol-Ang Słownik’ (Polish to English dictionary, http://slownik.freehostia.com) or alternatively you may place the search box on your web pages (and even allow visitors to your pages to search Polish words). To put the search box into your pages, simply copy and paste the following code into your page:
<script type=”text/javascript” src=”http://slownik.freehostia.com/ajax-searchbox.js”>
</script>
<script type=”text/javascript”>
var color_entry = ‘green’;
var color_def = ‘black’;
var color_owner = ‘gray’;
var color_ex = ‘gray’;
var size_owner = ‘80%’;
var size_ex = ‘80%’;
</script>
<title></title>
</head>
<body>
<div style=
“width:200pt;border:solid;border-width:1;border-color:blue;”>
<div id=”ajax_error”></div>
<div style=
“background:lightblue;border-bottom:solid;border-width:1;text-align:center”>
<h1 style=’display:inline;font-size:90%;font-family:sans-serif;’>
Pol-Ang Slownik (Polish-English)
</h1>
<form name=”jax_search_form” id=”jax_search_form”>
<input type=”text” name=”ajax_search_word” onkeypress=
“return checkEnter(event);”> <input type=”button” name=
“search_button” value=”Search” onclick=
“ajaxFunction()”><br>
<h1 style=
‘display:inline; font-weight:normal;font-size:70%’>
<a href=”http://slownik.freehostia.com” mce_href=”http://slownik.freehostia.com” >
</h1>
</form>
</div>
<div id=”ajax_contents”></div>
</div>
<!– end of code: Pol-Ang dictionary
(http://slownik.freehostia.com) search box –>
Free free to experiment with the code to change the layout of the text box. Cheers!
PS: I see quotes (” and ‘) have been altered by WordPress, or atleast it displays them all altered, but internally keeps the original. If it the case, change them to normal quotes.
To see how the search box looks like, please see here.