0

I want to rewrite requests to use index.php which is pretty standard and works.

The problem is that there are old and now invalid links which include the index.php and I want to redirect them to the root url of my site.

Potential duplicates include: Rewrite URL to index.php but avoid index.php in the URL, but the answers mentioned don't work for me.

RewriteEngine on

# This results in a redirect loop
#Redirect 301 /index.php http://domain.com

# This gets me a 500 error
# RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*)
# RewriteRule ^index\.php/?(.*) / [L,R=301]

# Push www traffic to base domain.  <<= Works
RewriteCond %{HTTP_HOST} !^domain.com$ [NC] 
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

# Final rewrite to include index.php   <<= Works
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]

The url: http://domain.com/index.php/component/fsf/?view=faq, should be invalid and it should return a 404 error but because of my current rewrite rules, a site visitor will see the main page. I want to redirect this with a 301 to the main page so it can be dropped from search indexes. Any help would be appreciated.

1 Answer 1

0

Change your THE_REQUEST rule to

RewriteCond %{THE_REQUEST} ^GET\ /index\.php(/.*) [NC]
RewriteRule ^ /? [L,R=301]
Sign up to request clarification or add additional context in comments.

1 Comment

Closer, it rewrote the specific example too [dbfront.com/?view=faq] and did not cause any further issues. I actually want the URL stripped of any garbage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.