If you are searching for URL rewriting examples you’ve been point to right place. We’ve some examples which can be very useful in many real time development/deployment scenario.
Let’s dive into some practical examples which can be useful in many scenarios:
Following example display “mysite.org/article-23.html” for “mysite.org/article.php?newsid=23″.
RewriteEngine on RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1 |
Following example display “mysite.org/headline/localnews/23.html” for “mysite.org/headline.php?newsid=23″
RewriteEngine on RewriteRule ^headline/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ headline.php?newsid=$2 |
Following example automatically redirect to www URL if user types some non www URL.
Example: if you type “mysite.org” it will automatically redirected to “www.mysite.org”.
RewriteEngine On RewriteCond %{HTTP_HOST} ^mysite\.org$ RewriteRule (.*) http://www.mysite.org/$1 [R=301,L] |
Following example display “http://www.mysite.com/123″ for “http://www.mysite.com/newsid=123″.
RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)$ article.php?newsid=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ article.php?newsid=$1 |
Following example point “http://www.mysite.org” to “http://www.mysite.org/russian”. This is simple example of pointing root folder to subfolder.
RewriteEngine On RewriteCond %{HTTP_HOST} ^mysite\.org$ [OR] RewriteCond %{HTTP_HOST} ^www\.mysite\.org$ RewriteCond %{REQUEST_URI} !^/russian/ RewriteRule (.*) /russian/$1 |

Leave a Reply
You must be logged in to post a comment.