url mod rewrite redirect wordpress

Posted under » Apache on 24 Jan 2019

This is what you see in the .htaccess of wordpress or other CMS.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

If you want to implement your own rewrite rules, you have to put it above the first [L] like so.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^whatyouseeurl$ 041.php
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

This redirection will work but the URL remains 041.php. If you want the URL to remain the same.. whatyouseeurl, then you have to put [L] at the end.

    RewriteRule ^whatyouseeurl$ 041.php [L]

Mod rewrite uses regex so this article won't make sense if you don't understand regex. Supposing you want to make a nice and easy to read URL.

RewriteRule    ^articles/([0-9]+)/?$   articles.php?abstarct=$1 [NC,L]

The [NC] you see means that is not case sensitive. So you can type arTIcles it will still work.

web security linux ubuntu GIT svn Raspberry apache mysql php drupal cake symfony javascript Ajax css