Vivek Kumar Bansal
Vivek Kumar Bansal

Reputation: 246

htaccess redirect not working. gives 404

I'm using slim framework and it has following .htaccess

Options -Multiviews
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)?$ index.php?url=$1 [NC,L,B,QSA,NE]
</IfModule>

I'm migrating an old site which has urls like index.php?q=about.

Now I want both index.php?q=about and /about/ to go to same page. So I tried this

Options -Multiviews
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^q=
Rewriterule ^index.php?q=(.*)$ index.php?url=$1 [R=301,NC,B,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)?$ index.php?url=$1 [NC,L,B,QSA,NE]
</IfModule>

But I'm getting 404 error. Can anybody help me out?

Update: mod_rewrite is enabled and /about/ is working fine. I need index.php?q=about to show the same page.

Upvotes: 1

Views: 41

Answers (1)

anubhava
anubhava

Reputation: 785128

You can use:

Options +FollowSymLinks -Multiviews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# redirect /index.php?q=about to /about
RewriteCond %{THE_REQUEST} \s/+index\.php\?q=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>

Upvotes: 1

Related Questions