Archive for the ‘Mode rewrite’ Category

Mode rewrite, quick fix | No Comments | April 26th, 2013

open .htaccess file and paste this code on top.

<FilesMatch “.*\.(htm|html|php)$”>
SetHandler application/x-httpd-php5

Mode rewrite | No Comments | December 13th, 2012

To implement such redirect using mod_rewrite and .htaccess you need to use RewriteMap directive which cannot be placed in .htaccess — only in server config / VirtualHost context. If you have such access:

1. Place this line inside <VirtualHost> block for your site:

RewriteMap lc int:tolower
2. Place this in your .htaccess:

RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]
This will redirect (301 Permanent Redirect) any URL that has at least 1 capital letter (Latin letters only) in path part of URL (query string is ignored) to the same but in lower case.

For example:

Mode rewrite, quick fix | No Comments | March 2nd, 2009

For that add this code in .htaccess file.

AddType application/x-httpd-php .php .htm .html

Mode rewrite, quick fix | No Comments | February 9th, 2009

want to redirect     to

add this code in htaccess file  ::

RewriteRule ^index.htm$ [R=301,L]

Mode rewrite | No Comments | October 22nd, 2008

See how to use .htaccess and mod_rewrite to easily transform ugly PHP URLs into search engine friendly ones.

The coming together of PHP and MySQL to create dynamic pages is a wonderful thing. Instead of having hundreds of separate webpages, your entire site can be stored inside a MySQL database, and then retrieved and displayed using a handful of “template” PHP pages. This makes updating the site extremely easy, though the draw back is often that the resulting URLs for the pages aren’t very search engine friendly. For example:

The “?” and “&” characters within the URL will stump many search engines, even Google, from crawling the page. What we want instead is something like:

which makes the URL appear just like any normal directory structure, with which all search engines have no qualms about. So how do we go about transforming the parameters portion of a dynamic URL into such a setup instead? Here are the simple steps:

Step 1: Rename your template PHP page, such as “articles.php”, as “articles” instead, without any extension. We want to use this page instead to act as our new templates page.

Step 2: Herein lies the key to creating search engine friendly URLs- configuring Apache to interpret a particular file without extension as a normal PHP page instead. In this case, we want Apache to treat “articles” as if it were a PHP page. In your .htaccess file, add the below code inside it:

ForceType application/x-httpd-php

Notice how the word “articles” appear within the tag. By adding the above code to your site’s .htaccess file, it informs Apache to interpret “articles” as a PHP page. You can add additional files for Apache to treat as PHP pages by duplicating the above multiple times.

Step 3: With “articles” now being synomonous to “articles.php”, all that’s left is writing code within “articles” to identify the parameters portion of our new URL format, and store them as variables for further processing. As a reminder, our new working URL looks like:

What we want is to create code that detects the “3” and “0” portion of the URL, as they are the parameters. Within “articles”, you could do the following:

//split the URL into parts using "/" as the delimiter:
$urlarray=explode("/", $REQUEST_URI);
//Contains "3", or the ID of the article to display:
//Contains "0", or the page number of the article in question:

We now have two variables that contain the two parameters embedded inside our search engine friendly URL, which we can then pass into a MySQL query to display the corresponding article and page number. For example:

$getarticle=mysql_query("SELECT thearticle FROM articletable
WHERE id=$articleID AND page=$pageNum");
echo mysql_result($getarticle, 0); //displays article

And there you have it. As mentioned, the key to creating search engine friendly URLs in PHP and MySQL is in fact via Apache’s .htaccess file.