Latest Post
Tampilkan postingan dengan label htaccess. Tampilkan semua postingan
Tampilkan postingan dengan label htaccess. Tampilkan semua postingan

.htaccess Rewrite Rule Examples to Achieve Clean URLs

Written By Unknown on Minggu, 22 September 2013 | 10.11

Our code for today will make your website URLs clean and attractive. Clean URLs are user and SEO friendly, it does not contain any query string (e.g. param1=something&id=1111) thus giving your users and search engines (like Google) an idea what your link is all about once it was shared or indexed.

To read more about this article Click Here

For Demo Click Here

To download files Click Here

Block Proxy Server via .htaccess

Written By Unknown on Kamis, 22 Desember 2011 | 08.28

 I wrote .htaccess code for blocking proxy server. If you want to block proxy server using .htaccess than just write below code in .htaccess file and you rocks.
RewriteCond %{HTTP:VIA} !^$ [OR]
RewriteCond %{HTTP:FORWARDED} !^$ [OR]
RewriteCond %{HTTP:USERAGENT_VIA} !^$ [OR]
RewriteCond %{HTTP:X_FORWARDED_FOR} !^$ [OR]
RewriteCond %{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:HTTP_PC_REMOTE_ADDR} !^$ [OR]
RewriteCond %{HTTP:HTTP_CLIENT_IP} !^$
RewriteRule ^(.*)$ – [F]

Block Proxy Server using .htaccess, Block Proxy Server via .htaccess, Block Proxy using .htaccess, .htaccess code for Block Proxy, .htaccess tricks for Proxy Block.

How to remove index.php from url using .htaccess (mod_rewrite)

Written By Unknown on Senin, 19 Desember 2011 | 08.47

For better SEO optimization and make urls more search engine friendly , remove index.php from URL and make it easier to read.

Remove index.php from URL can be done by writing only two lines in your .htaccess(mod_rewrite in apache) file. Before writing this rule in .htaccess , make sure that your mod_rewrite is enabled(On) in your apache server. 


Most probably mod_rewrite is enabled in Linux server but for windows server , you need to contact hosting people to make mod_rewrite enabled. You can check this by looking in phpinfo().


Below is the Rules which will remove index.php from URL using .htaccess. Look at below links for .htaccess rules.


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\
HTTP/ RewriteRule ^(([^/]+/)*)index\.php$ http://www.%
{HTTP_HOST}/ [R=301,NS,L]



Redirect 301 means Moved Permanently so most search engines will remove index.php from URL.

Force WWW onto Domain Name URLs for SEO with .htaccess

Written By Unknown on Minggu, 20 November 2011 | 09.01


You can get to a website by typing http://mydomain.com or by typing http://www.mydomain.com. So should this matter to you as a developer? Yup. Google doesn’t like when you have duplicate content on a website.


To make sure that Google doesn’t consider the content, or traffic, to the ‘non-www’ and the ‘www’ versions the same, it’s a good idea to either force the www, or to force remove the www from the URL when people enter the site. This way no matter what people enter as the URL, the effect is the same to your site.

So which to use? It’s up to you. From personal experience I’ve found that business owners tend to want the www if givin the choice, where people that actually know what they’re talking about  like shorter URLs and prefer to remove the www. 

I HATE seeing the ‘www’, both in URLs, and while we’re at it in any type of advertising, business cards, etc. The ‘.com’ implies the ‘www’, duuuh.

Below is the code you’ll need to add to your .htaccess file to either remove or to add the www to the URL.

# ---------------------------------------------------------------------- # Start rewrite engine # ---------------------------------------------------------------------- <IfModule mod_rewrite.c>   RewriteEngine On </IfModule> # Option 1: # Rewrite "www.domain.com -> domain.com" <IfModule mod_rewrite.c>   RewriteCond %{HTTPS} !=on   RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]   RewriteRule ^(.*)$ http://%1/$1 [R=301,L] </IfModule> # ---------------------------------------------------------------------- # Option 2: # To rewrite "domain.com -> www.domain.com" uncomment the following lines. # <IfModule mod_rewrite.c> #   RewriteCond %{HTTPS} !=on #   RewriteCond %{HTTP_HOST} !^www\..+$ [NC] #   RewriteCond %{HTTP_HOST} (.+)$ [NC] #   RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L] # </IfModule>
 
 
code from html5boilerplate.com

Uploading large(big) files in PHP using .htaccess

Written By Unknown on Jumat, 30 April 2010 | 03.29


I’ve seen that many of my friends are struggling with the uploads of the bigger or larger files in PHP. After looking at their struggle, i’m here to solve the problem of uploading larger or bigger files in PHP.

Most of the web servers are configured such a way that a user can only upload the maximum file size of 2MB. So there might be the problem for the people who wants to upload the .pdf file of size around 15MB. But, you can increse the maximum upload file size limit by using .htaccess file.
Here is a small tips for you which you can use to upload such a large file using file field of the form and move_uploaded_file() function in PHP.
1) Create a .htaccess file in the root folder of web server.
2) Put the following code in side the .htaccess file and save it.
php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200


Now you can upload the file-size up-to 20MB in a simple way using file field in your html form and move_uploaded_file() function available in PHP. In the above .htaccess file, uploading capability is increased by the four parameter first one is maximum file size for uploading, second one is maximum size of the post data , third one is maximum time in seconds a script is allowed to run before it is terminated by the parser and last one is maximum time in seconds a script is allowed to parse input data such as like file uploads, POST and GET data.
You can change the above parameter to upload the bigger file size than 20MB.

Hide .php extension with url rewriting using .htaccess


I’m going to show you how to rewrite the URL instead of renaming the file extension Using this technique you will see product.html in the address bar of the browser but the actual file name remains product.php and you don’t need to rename the file extension. Furthermore you can rewrite the URL like product.php?id=5 to product-5.html.

what is the benefits of rewriting URL?

When a search engine visits the dynamic url like product.php?id=5 it does not give much importance to that URL as search engine sees “?” sign treat it as a url which keeps on changing. so we’re converting the dynamic URL like the product.php?id=5 to static url format like product-5.html. We’ll rewrite the url in such a way that in browser’s address bar it will display as a product-5.html but it actually calls the file product.php?id=5. So that why these kind of URL also named as SEO friendly URL.

what is required for URL rewriting ??

To rewrite the URL you must have the mod_rewrite module must be loaded in apache server. And furthermore, FollowSymLinks options also need to be enabled otherwise you may encounter 500 Internal Sever Error. 

Examples of url rewriting for seo friendly URL

For rewriting the URL, you should create a .htaccess file in the root folder of your web directory. And have to put the following codes as your requirement.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [nc]

The following example will rewrite the test.php to test.html i.e when a URL like http://localhost/test.htm is called in address bar it calls the file test.php. As you can see the regular expression in first part of the RewriteRule command and $1 represents the first regular expression of the part of the RewriteRule and [nc] means not case sensitive.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ products.php?id=$1

The following example will rewrite the product.php?id=5 to porduct-5.html i.e when a URL like http://localhost/product-5.html calls product.php?id=5 automatically.

5 useful url rewriting examples using .htaccess


If you are looking for the examples of URL rewriting then this post might be useful for you. In this post, I’ve given five useful examples of URL rewriting using .htacess. 


Now let’s look at the examples

1)Rewriting product.php?id=12 to product-12.html
It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.
RewriteEngine on

RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1


2) Rewriting product.php?id=12 to product/ipod-nano/12.html
SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.
RewriteEngine on

RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2


3) Redirecting non www URL to www URL
If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. 
RewriteEngine On

RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]


4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1


5) Redirecting the domain to a new subfolder of inside public_html.
Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.
RewriteEngine On

RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger