.htaccess file won't work - .htaccess

I'm running my app in XAMPP with CodeIgniter. I have a .htaccess file that will not necessitate me anymore of including index.php in url but it won't work.
The content of my .htaccess file is
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|crossdomain\.xml|captcha|images|assets|archive|css|js|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
I already set the all the directories with AllowOverride to All. I've already enabled mod_rewrite too but still my links won't work. Instead of going to the specified URL, it will go the XAMPP homepage.
Also in my config file, it looks like this:
$config['base_url'] = '';
$config['index_page'] = '';
Then in view:
a href="/signup"
Am I doing it right? Please help.

Try
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|monitor\.php|resources|test_gui|img|css|js|favicon\.ico|(.*)\.(png|js|jpg|swf|css|gif|ico|jpeg|scss)$)
RewriteRule ^(.*)$ index.php/$1 [L]

Related

.htaccess not working on server

I have hosted a site as a sub folder like "http://www.sitename.com/projectfoldername/".
Here it shows only the home page and when clicked on any menu it shows 404 error ,so i changed the the url by writing index.php before the controller name now the url has changed from this:
"http://www.sitename.com/projectfoldername/controller-name/function-name" to this: "http://www.sitename.com/projectfoldername/index.php/controller-name/function-name" then it shows the pages but worked locally only..
my htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
config.php
$config['base_url'] = 'http://www.sitename.com/projectfoldername/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
If you used Apache Web Server, active your mod_rewrite
On Ubuntu:
sudo a2enmod rewrite
On Window:
Open your httpd.conf and Find the line
#LoadModule rewrite_module modules/mod_rewrite.so and remove the hash ‘#’
Use RewriteBase /projectfoldername in your .htaccess file like so:
RewriteEngine On
RewriteBase /projectfoldername
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
try adding following in .htaccess, it might help you.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
#antroo ghosh , At first you have to know that which web server is using( Apache or IIS).
If you are using windows(IIS) server you can't use .htaccess, In IIS you have to use web.config instead of .htaccess.
For more details https://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig
I hope this may helps you!

codeigniter .htaccess works fine in localhost server but not in web server

.htaccess works fine in my xampp server but when I uploaded it to the web server, it gives me this error"404 Page Not Found The page you requested was not found."
here are my configs.
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
and my .htaccess is
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
I place my codeigniter in a subfolder /sibulanAdmin
http://sibulanlgu.spillworks.net/sibulanAdmin/
This cost me a lot of time searching in the web, but no solutions works for me.
please help
Try this htaccess below, it works for me I have xampp and works fine on live server
And Change
$config['uri_protocol'] = 'REQUEST_URI';
To
$config['uri_protocol'] = 'AUTO';
htaccess
Options +FollowSymLinks
Options -Indexes
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
Order deny,allow
Deny from all
</FilesMatch>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
As your provided information, your .htaccess should be like this.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /sibulanAdmin/index.php/$0 [PT,L]
Make sure mod rewrite is enable on your server. If not yet, you should follow on this answer and this tutorial. Hope it will be work for you.
Edit
You can enable mod rewrite by typing in terminal like that :
a2enmod rewrite
And then, don't forget to set AllowOverride to all of document root in your apache configuration. In your apache2.conf, (/etc/apache2/apache2.conf in my case)
<Directory /var/www/>
AllowOverride All
</Directory>
Finally, just need to restart your server.
service apache2 restart

Codeigniter 2.1.4 installation in sub directory

I have successfully installed CI in the root directory many times, but now I have been forced to install CI in https://mydomain.com/mvc
There exists one controller "Login" with one action "index"
The .htaccess file looks like:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /mvc
RewriteRule ^(.*)$ index.php?/$1 [L]
In config/config.php
$config['base_url'] = 'https://mydomain.com/mvc/';
$config['index_page'] = '';
My routes look like:
$route['default_controller'] = "login";
$route['login'] = "login/index";
$route['404_override'] = '';
mod_rewrite is enabled
https://mydomain.com/mvc gives a 404
https://mydomain.com/mvc/login gives a 404
What do I miss?
What´s your hosting? if is hostgator you need add your user.
Try this
RewriteEngine On
RewriteBase /mvc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mvc/index.php/$1 [L]
if your hosting is hostgator you need add you name user, for example
RewriteEngine On
RewriteBase /~<name_user>/%{HTTP_HOST} <or> <your folder>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~<name_user>/%{HTTP_HOST} <or> <your folder>/index.php/$1 [L]
Try this
Set you default base url for subdirectory
$config['base_url'] = "http://www.example.com/subdir/"
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
In some cases the default setting for uri_protocol does not work properly. So you have just replace it
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This code run all sub directory. Hope this will help you!.
try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mvc/index.php?/$1 [L]
I had the same issue and I could fix it by updating /etc/apache2/sites-enabled/000-default.conf file
try this.
mvc/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
mvc/application/config/config.php
$config['base_url'] = 'https://yourdomain.com/mvc/';
/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
....
<Directory /your/root/directory> # /var/www/html
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Trouble with .htaccess mod_rewrite

Please can somebody take a look at my .htaccess code to help identify what's wrong.
I am trying to amend all example.php, example.html and example.htm URL's to index.php?filename=example.html
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(index\.php) - [L]
RewriteRule ^([^/\.]+).(php|html|htm)$ index.php?filename=$1.html&%{QUERY_STRING} [L]
</IfModule>
When I enter a URL like example.html I'm taken to the default 404 and not index.php
Try:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
I'm not using the apache .hatacces for a while,
But try this one:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !^.*/(css|img|js)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?filename=$1&%{QUERY_STRING} [L]
Basically what you need is to be sure that the URL didn't have already index.php. You accomplish it with RewriteCond.
After you redirect all to index.php passing the filename as a parameter.
You can add more exception to the RewriteCond like on this example, all content with /css, /js, /img will not pass to this rule.
You can check this thread: Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests also

.htaccess Error in Codeigniter

I am new to Codeigniter I have put an .htaccess in root folder of codeigniter 2.1.3.
I have tried my .htaccess file on both xampp & wamp server but this is not removing my index.php.
I have also set
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
and here is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|system\/plugins|robots\.txt|css\/)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
i dont know why this is not removing my index.php page from url.
help me!!
Open config.php make sure to change $config['uri_protocol']= 'REQUEST_URI';
and in place this code in .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|indexcp\.php?|resources|robots\.txt)
RewriteRule ^([A-Za-z0-9_/.-]+)$ index.php?/welcome/$1
That's all it works for me. Let me know if you are still facing any problem.
Check whether rewrite_module is configured as on
And try removing the condition from your code:
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|system\/plugins|robots\.txt|css\/)
RewriteRule ^(.*)$ index.php/$1 [L]
I used this code in my project it works for me,
.htaccess :-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
config.php :-
$config['index_page'] = '';
$config['base_url'] = 'http://www.example.com/';
I hope this will help you
Another sily problem that could be done is that the folder that contains the application is not 755.
For be more sure about what is the problem look your apache log file , in linux /var/log/apache/error.log

Resources