Creating SEO friendly URL requires a knowledge on how htaccess works. Not just that, you should also be familiar with Regular Expressions but I won’t cover that one in this post though since we’ll be focusing on putting those in htaccess. Now, let’s get our hands dirty.
For example:
http://mysite.com/profile.php?username=JuanDelaCruz
If you wanted that one to become
http://mysite.com/user/JuanDelaCruz/
This is what you’re going to do:
#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}\.php -f
#RewriteRule ^(.*)$ $1.php
# Use the following rule if you want to make the page like a directory
RewriteCond %{REQUEST_URI} !^/user/profile.php
RewriteRule ^user/(.*[^/])$ user/$1/ [R=301,L]
# The following rewrite the other way round:
RewriteCond %{REQUEST_URI} ^/profile.php
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /profile.php
RewriteCond %{QUERY_STRING} id=([^&]+)
RewriteRule ^profile.php$ user/%1?
There are comments, so hope you can understand it from there.
Hope this helps someone! Have a Happy Coding!
TweetHowdy! I will show you how to create a zip file in PHP. All the directory in your server will also be zipped in the code. I will use the ZipArchive class in php. It’s easy as 1 2 3 function ListFiles($dir) { if($dh = opendir($dir)) { $files = Array(); $inner_files = Array(); while($file = readdir($dh))…
Continue Reading »
TweetI will show you how to display all database records of a certain table in a dropdownlist in Yii. Model Code: class UserType extends CActiveRecord { public function GetUserType(){ $connection=Yii::app()->db; $command= $connection->createCommand("SELECT * FROM ".$this->tableName()); $rows = $command->queryAll(); return CHtml::listData($rows,'id', 'type'); } } View Code: echo $form->dropDownList($model,'user_type_id',UserType::model()->GetUserType()); The CHTML::listData() takes 3 parameters. 1st is the…
Continue Reading »
TweetHere’s how to specify a date validation rules in the Model. The idea here is that “Date To” should always be greater than “Date From”. Here’s how to do that public function rules() { return array( array( 'date_to','compare','compareAttribute' => 'date_from','operator'=>'>', 'allowEmpty'=>'false', 'message' => '{attribute} should be greater than "{compareValue}".'), ); } Piece of cake eh?…
Continue Reading »
TweetI’m working on implementing Paypal Subscription API in PHP for the past weeks, I thought this was kinda complicated just like the DirectPayment method API. Guess what, it was just a piece of cake, i’ll show you my code: <form name="_xclick" id="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal – it's…
Continue Reading »
Tweet5ad3izx5tyarjaj I will show you how to setup AWeber Email Parser. To those of you who do not know what Aweber is, it is an email marketing software that allows you to store email addresses and other important stuffs to people who uses your product or whatever purpose you have. So my idea here is…
Continue Reading »