SPIP & htaccess. Examples of use.

A few samples for using htaccess primarily to redirect in SPIP. In general, they are fairly banal and common, that would make another list of examples, but on the other hand, some problems are unique to SPIP. And they require either good knowledge of ModRewrite or strong skill in using Google.

Redirect from one URL to another

Basically, we use redirects after finishing the website re-design. Re-design is usually accompanied by a change website CMS to SPIP.

If the web site has a strong history, most of the its pages are already indexed. We had to "save" the links in the Google Index. That’s why we make 301 redirect from previous URL to a new SPIP one. If we do not there would be a lot of 404 error during some next week and website position in Google search result would be weaken.

Example №1. Very Simple.

from: http://domain.com/Glavnaya.html
to: http://domain.com/
Redirect  301  /Glavnaya.html  /

Example №2. The same.

from: http://domain.com/tehnology
to: http://domain.com/spip.php?rubrique6
RedirectMatch  301   ^/tehnology$   /spip.php?rubrique6

Example №3. Bit harder.

from: http://domain.com/tehnology/36
to: http://domain.com/spip.php?article23
solution: RedirectMatch  301  ^/tehnology/36$  /spip.php?article23

Example №4. Redirecting dynamic SPIP URLs.

from: http://domain.com/spip.php?article56
to: http://domain.com/spip.php?rubrique69


RewriteCond %{QUERY_STRING}        ^article56$
RewriteRule ^spip\.php$ /spip.php?rubrique69 [L,R=301]

Example № 5. Redirect to page with variable.

from: http://domain.com/index.php?page=chi-siamo.html
to: http://domain.com/?lang=it


RewriteCond %{QUERY_STRING} .chi-siamo\.html$
RewriteRule ^index\.php$ ?lang=it [L,R=301]

Redirect vs duplicated home pages

Example № 1. Duplicated home page URL.

Once we had done replacement the website CMS from Joomla to SPIP. Our SEO company sent us tech brief for adopting the website for better SEO guideline.

We did almost everything but one task was rather difficult. Home page URL stored in the Google Index was http://domain.com/index.php. The new one (after we’d finished SPIPing the website) changed to http://domain.com/. We had to do a redirect.

from: http://domain.com/index.php (index.html)
to: http://domain.com/


RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html)\ HTTP
RewriteRule ^(.*)index\.(php|html)$ /$1 [R=301,L]

Example № 2. Multilingual home page.

We have a website http://domain.com, primary language site in Russian, the main page will be available with two references:
- http://domain.com
- http://domain.com/?lang=ru.

from: http://domain.com/?lang=ru
to: http://domain.com/


RewriteCond %{QUERY_STRING}  ^lang=ru.*$
RewriteRule ^  /? [R=301,L]

Simple pretty redirects

Example 1. Link /? Lang = ru

Again, multi-language sites. A link like http://domain.com/?lang=ru functional, but not beautiful. Where reference is prettier species http://domain.com/ru.

solution:RewriteRule  ru$  /?lang=ru [QSA,L]

Example 2. Direct link to the custom template

from: http://domain.com/cart
to: http://domain.com/?page=cart
RewriteRule ^cart$      spip.php?page=cart [QSA,L]

Site in multiple languages with multiple domains

Suppose we have a website with two language versions - English and Russian. And two domains domain.com and domain.ru for each version, respectively.
We need to get the entry for domain.com we fall strictly to the English version of the site.

To do this, we provide hosting settings domain.com domain as alias to domain.ru (or as a domain pointer) and add the following rule for mod_rewrite:


RewriteCond %{HTTP_HOST}  ^www.domain\.com$
RewriteRule (.*) spip.php?lang=en [QSA,L]

Generic redirects

htaccess redirect www to non-www

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


It could be some errors in my redirect samples. If you notice any, pls email me ss1945@gmail.com. I will correct.

to top