My customer accountSales contactWebmailOVHcloud Blog

Welcome to OVHcloud.

Log in to order, manage your products and services, and track your orders

Log in
OVH Guides

URL rewriting using mod_rewrite

Find out how to use .htaccess to rewrite URLs

Simple redirection

  • Edit the .htaccess file:
RewriteEngine On
RewriteRule .* testing.php

This code redirects each request to the testing.php script.

  • or:
RewriteEngine On
RewriteRule letstest /test_wslash/testing.php

This code redirects each /letstest request to the /test_wslash/testing.php script.

Redirect to

  • This restricts website access to, which is good for SEO:
RewriteEngine on
Rewritecond %{HTTP_HOST} ^$
Rewriterule ^(.*)$1 [QSA,L,R=301]

Redirect to a particular folder without displaying the folder in question

  • If your website is not in the target folder, this will force all requests to use, when in reality the page is called:
RewriteEngine on
Rewritecond %{HTTP_HOST} ^
Rewritecond %{REQUEST_URI} !^/MySite
Rewriterule ^(.*)$ /MySite/

URL rewriting

mod_rewrite enables URL rewriting

  • .htaccess :
RewriteEngine On
RewriteCond %{REQUEST_URI} !testing.php
RewriteRule (.*) testing.php?var=$1

These rules run the testing.php script with the GET variable containing the URL.

  • php:
print("testing server <br/>\n");
print("var: {$_GET['var']}\n");

Automatically redirect visitors to SSL when they visit the unsecured version of the website

The mod_rewrite module enables you to rewrite URLs.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

These guides might also interest you...