user3138111
user3138111

Reputation: 559

htaccess rewrite rule is not working

All,

I'm trying to redirect the hits via htaccess redirect scripts.

Below is my htaccess scripts.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/(.*)/$ post.php?tag=$1 [L]
RewriteRule ^search/(.*)$ search.php?tag=$1 [L]

Issue : Index and search page are getting redirected. Post page is not getting redirected.

Please help on how to fix it

Upvotes: 0

Views: 72

Answers (2)

kittykittybangbang
kittykittybangbang

Reputation: 2400

Apache out of the box doesn't allow use of htaccess files. If you haven't edited your /etc/apache2/sites-available/default file, you'll need to do so. Look for this chunk of code:

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
            # Uncomment this directive is you want to see apache2's
            # default start page (in /apache2-default) when you go to /
            #RedirectMatch ^/$ /apache2-default/
    </Directory>

And change AllowOverride None to AllowOverride All. After you've changed that, you'll need to restart Apache for the changes to take place (service apache2 restart).

Caveat

Most of what you'd want to do via htaccess files can be done more securely via the Apache configuration files (hence the htaccess files are ignored by default). See this post for details.

Upvotes: 0

anubhava
anubhava

Reputation: 786291

Try this in your root .htaccess:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^post/(.+)$ post.php?tag=$1 [L,NC,QSA]

RewriteRule ^search/(.+)$ search.php?tag=$1 [L,NC,QSA]

Upvotes: 1

Related Questions