Disable www.mywebsite.com/index.php/route access
My website can be view from 2 different kind of URI:
www.mywebsite.c开发者_StackOverflowom/magazine or www.mywebsite.com/index.php/magazine
It makes a copy of my website which is very bad for Google SEO. Someone have any idea how to disable the index.php browsing?
This is my htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Use a mod_rewrite
to write a RewriteRule
to do a permanent redirect from /index.php/magazine to /magazine.
EDIT 5/21/11 9:40am EST
After some "quick" testing, I realized that the below rule won't work if youre trying to apply it to a sub-folder in your document root (eg: www.mysite.com/test/index.php/go/somewhere). This is because of the way mod_rewrite
works, which is documented on the Apache mod_rewrite
Documentation and says that:
Note: Pattern matching in per-directory context
Never forget that Pattern is applied to a complete URL in per-server configuration files. However, in per-directory configuration files, the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done. This feature is essential for many sorts of rewriting - without this, you would always have to match the parent directory which is not always possible. There is one exception: If a substitution string starts with '
http://
', then the directory prefix will not be added, and an external redirect or proxy throughput (if flag P is used) is forced!
So, if your .htaccess
file is within a sub-directory, your RewriteRule
becomes:
RewriteEngine On
RewriteRule ^index\.php(/.*)$ /sub-dir-name$1 [R=301,QSA,L]
Otherwise, if you're rewriting from the root of the domain, it is:
RewriteEngine On
RewriteRule ^index.php(/.*)$ /$1 [R=301,QSA,L]
Hope that works for you!
精彩评论