2

I want that if someone got link to my site, lets say: www.bla.com/index.php , he will redirect to www.bla.com. or in another words - remove the index.php.

Here is my .htaccess file:

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

Either if someone got link: www.bla.com/camera/index.php - it will redirect to www.bla.com/camera/.

For now, the site itself works great, without index.php, but i want to remove the index.php if someone came from extern link.

1

5 Answers 5

2

This post is tagged with WordPress. All of what you're looking for and doing (canonical domain, canonical url without index.php) has been built into WordPress at least since WP 3.0 when permalinks are turned on... Look into canonical redirects -- you'll find the logic in there.

Sign up to request clarification or add additional context in comments.

5 Comments

The posts works great, without index.php. what i want - that if i give you link to my site, for example: bla.com/index.php - you will redirect to bla.com
That works already unless you've messed around with rewrite rules and canonical redirects... Have you tried? :-)
The SEO man evidently doesn't know much WordPress, or (if I may add) of what he's talking about for that matter (since WP also publishes canonical urls as a meta tag, rendering the point completely moot). :-)
Ok, so i think you helped me !
As an aside, if he advised you to use /%postname%/ or something to that order as your site's permalink, you're setting yourself up for enormous performance problems (and crippled SEO) if you start adding more than a few static pages. If he did, ignore him and select the default date/name based rule, which performs fine, offers better UI, and doesn't trigger verbose rewrite rules in WP.
2

try like that in

.htaccess

RewriteEngine On

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

RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
RewriteRule ^(.*)$ index.php?/$1 [L]

Comments

1

Try this

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

Comments

1

With this code, you will be returned to the index.php page:

wp_redirect( home_url() );
exit;

enter image description here

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

I believe the OP wants to prevent using index.php even when external links are involved. After following the advice from the other question. Try this.

RewriteRule ^(.*)/index.php$ http://www.bla.com/$1/ [L,R=301]

1 Comment

Thank you. You understand my question, i try this line but it still have the index.php.

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.