I am using CodeIgnter, as for a result all my links are like base.com/index.php/home/index
or www.base.com/index.php/home/index
.
I would like to display them only as base.com/home/index
if possible.I have tried looking over the internet,got the rewrite in htacces from both of them as:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [PT,L]
RewriteCond %{HTTP_HOST} ^domain\.com\$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com\$
RewriteRule ^/?$ "http\:\/\/domain\.com\/" [R=301,L]
and
RewriteEngine on
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
put them separately,they work.But toghether they don't do what i need them to do. Anyone knowing the solution?Thanks.
For CI, you want something like your first set of rules, but without the redirect. But the redirect needs to happen before the routing happes, so try:
RewriteEngine On
# redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.base\.com$ [NC]
RewriteRule ^(.*)$ http://base.com/$1 [L,R=301]
# redirect direct requests to /index.php to remove it
RewriteCond %{THE_REQUEST} \ /index\.php/?([^\?\ ]*)
RewriteRule ^ http://base.com/%1 [L,R=301]
# internally route to /index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [PT,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With