Using Htaccess, I am able to remove the www from the url but im struggling endlessly with completely removing the index.php.
I am using the codeigniter framework and I checked my config file.
$config['index_page'] = '';
$config['base_url'] = '';
Ive also tried: as someone suggested elsewhere on S.O:
$config['base_url'] = '/';
My htaccess file looked like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301]
Ive tried all the different versions of writing the mode-rewrite rule, this one works the best but it adds a question mark to the URL and a forward slash RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?/$1 [L,QSA]
The result at the moment, if i type www.mywebsite.com, it will change to mywebsite.com, which is correct.
But if I type www.mywebsite.com/someuri then it becomes www.mywebsite.com/index.php?someuri
with the last modrewrite rule the url becomes www.mywebsite.com/?/someuri
I then tried adding the question mark after index.php like this:
# Now the CodeIgniter part
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
With the latter, if i type index.php into the URL, it doesnt go away.
I clearly dont understand mod-rewrite, can someone please guide me in the right direction.
[L,R=301]in your forcing non-www rule. TheLindicates last rule, so don't process any further. Try removing that from there. I can't test it at the moment for it to be an answer, I'm not at a machine with Apache installed.