I've tried pretty much everything i can think of, I've basically moved from Mac OS to Windows OS webserver with my project (testing essentially). When i access any other page from my server I get the "Page Not Found" error, however it works if i add index.php/location, anyway here is some of my settings:
Initially i have checked if mod_rewrite is enabled by adding this: in_array('mod_rewrite', apache_get_modules()) to a conditional statement which responded as true so i know mod_rewrite is in face enabled.
Here is my .htaccess file which is located in the main directory of my project (with index.php):
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Have also tried as RewriteRule ^(.*)$ index.php/$1 [L] and written it outside the <ifModule> tags.
Here are some of my codeigniter settings:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I have also tried including the index.php in the index_page and tried REQUEST_URI for the uri_protocol and nothing seems to be working.
Sidenote: It runs perfectly on my mac and linux (Raspberry Pi).
Can you suggest any alternative methods or spot something I've missed.
EDIT:
httpd.conf i have done the following
<directory />
Options All
AllowOverride All
</directory>
ALL instances of AllowOverride None have been changed to AllowOverride All
The following has been uncommented/enabled:
LoadModule rewrite_module modules/mod_rewrite.so
Do not touch your default .htaccess file in php.
Make a new file in your codeigniter root directory named ".htaccess"
Paste below code into this new file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /leo/index.php/$1 [L]
Save it and it should work now.
Related
In the past, I have got this working no problems at all, but for some reason on my new server I just can't get it to work.
I have the following .htaccess file in the root of my application
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have also enabled mod_rewrite and have confirmed this with php_info()
my site is located at /var/www/html/test
Is it possible that although mod_rewrite is enabled that it is not working and if so, how can I test it?
On some server implementations, you'll need to wrap it within <IfModule> tags.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Also check your httpd.conf file to ensure it has:
Options FollowSymLinks
AllowOverride All
It'd also be worth checking to makesure the .htaccess file isn't being overridden by another .htaccess file.
A simple way to test if .htaccess is working
Simply put the following in your .htaccess file:
deny from All
What this does is deny access to your site from everyone. If you are presented with a 403 forbidden when trying to access the site - the .htaccess file is being included. If not - see above.
I use this on my codeigniter setup
RewriteEngine on
# prevent these directories from hitting CI
RewriteCond $1 !^(index\.php|images|assets|robots\.txt|crossdomain\.xml)
# route everything else to the index.php
RewriteRule ^/(.*)$ /index.php/$1 [QSA]
(my setup is done in the virtualhost of .conf and not in .htaccess, though they are usually about the same configuration)
I'm using Ubuntu 13 with the following setup for a local codeigniter site.
Apache/2.4.6 (Ubuntu)
5.5.3-1ubuntu2.2
'CI_VERSION', '2.1.2'
And URLs are no longer working without index.php. They used to work, but after upgrading from Ubuntu 12.x to 13.x and a few apache updates over the past year, the localhost sites no longer work right.
if I go to localhost/index.php/controllername/ it works but if I go to localhost/controllername/ it does not.
mod_rewrite is enabled.
CodeIgniter config has:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; // tried all available options here and
Nothing worked
in the .conf file for the domain I have this:
<Directory />
Options -Multiviews +FollowSymLinks
AllowOverride All
</Directory>
and here's the .htaccess file commented lines are ones I tried that didn't work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# RewriteCond $1 !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# RewriteRule .* index.php/$0 [PT,L]
# RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I’ve Googled and read everything I can find and tried everything I could find including several posts here on Stack Overflow, including the ones in the “Questions that may already have your answer.” Still nothing seemed to work. But like I said, this worked in the past, but only after multiple updates to the OS and Apache did I first notice it stop working.
I’ll be moving away from CodeIgniter with future projects, but these projects already existed. Baffled as to what could be the issue.
SOLUTION:
turns out it was not a codeigniter issue at all. It was an apache issue but not with the rewrite rules.
in my apache2.conf I had to alter the block for /var/www/
Require all granted seems to have done the trick.
DirectoryIndex index.php index.html
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
just for good measure, I made the change here as well:
Options FollowSymLinks
AllowOverride All
Require all granted
found on askubuntu
https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working
copy following code to .htaccess in your root folder
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Options All -Indexes
This works fine for me to remove index.php in CodeIgniter.
It doesn’t seem like CodeIgniter has a default .htaccess, so unclear where that came from. But for debugging purposes, I would recommend you do the following. First, here is your .htaccess all cleaned up:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Now replace your index.php with this. It just dumps the $_GET values passed via the .htaccess like so:
echo '<pre>';
print_r($_GET);
echo '</pre>';
Now with that in your .htaccess load the index page of the site/app/project in question. The output should be something like this:
Array
(
[/controllername/here/] =>
)
Which appears to be correct. But again, you would know better than us.
The purpose of doing this is to assess whether the issue is either in Apache passing proper $_GET values to your CodeIgniter setup, which is one issue. Or whether the issue is within your CodeIgniter controller logic itself.
My gut tells me the issue is in the CodeIgniter logic in your codebase since the upgrade from Ubuntu 12.x to Ubuntu 13.x includes an upgraded version of PHP from version 5.3 in Ubuntu 12.x to version 5.5 in Ubuntu 13.x. I am using lots of code that works in PHP 5.3 and PHP 5.4 but breaks at times in PHP 5.5 since there are major changes in that codebase that will cause code to break if you don’t keep on top of non-depreciated functions & such.
I would try something like:
RewriteRule ^(?!index)(.*)$ index.php?/myvariable=$1 [L]
If you know what GET variable the script is expecting for controllername in localhost/controllername, then in the rule replace myvariable with that variable name.
Place the .htaccess file in the project folder like this:
htdocs/your_project/.htaccess
Try this new code for .htaccess:
RewriteEngine on
RewriteBase /your-project-directory-name/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I have the following URL on my localhost:
http://localhost/?cmd=causeListByCourtName
http://localhost/?cmd=here could be any other page name
I have tried to rewrite the URL like =
http://localhost/page/causeListByCourtName
I have tried this:
RewriteEngine On
RewriteRule ^pages/(.+)/?$ .+/?cmd=$1 [NC,L]
# Handle pages requests
But it do nothing. I am using XAMPP on my windows 7.
in my httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so
is already enabled. What I am doing wrong?
You need to also make sure you changed AllowOverride None to AllowOverride All in your httpd.conf file wherever you find it.
Try doing it this way.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.+)/?$ /?cmd=$1 [NC,L]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^page/(.*)$ index.php?cmd=$1 [L]
This in case you use index.php as your default page. You can cut down the index.php from the front
I know this question is more appropriate for Server Fault but unfortunately I was banned for poor quality questions (I was down voted on 2-3 questions I asked.) So the next best place to ask these questions are here.
I have two problems related to CodeIgniter routing.
The first problem is that I can't seem to get rid of index.php in the url. I followed the instructions on how to remove it. I have the following mod rewrite code in my .htaccess file (see below) at the root of my WAMP server (CI is located at the root, not in its own folder). I have uncommented this line in httpd.conf file LoadModule rewrite_module modules/mod_rewrite.so. I deleted index.php from $config['index_page'] = "index.php";. And I restarted all WAMP services.
My second problem is that I have a controller called search and a method called index. I would like to change the resultant URL from http://localhost/index.php/search/index to http://localhost/search/whatever_im_searching_for. I tried the following custom route in my routes.php file but it did not work: $route['search/(.*)'] = "search/$1";
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/
RewriteBase /
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
I am struggling to understand the code in .htaccess and on how to use CI's custom routing. Any assistance will be greatly appreciated. Thank you in advance.
EDIT 1
Edit your htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
To have your searchterms in the url you can look at this:
https://stackoverflow.com/a/12070284/1379394
Second problem:
$route['search/(:any)'] = "search/index/$1";
Check Apache's default config file. On WAMP it's probably in
<WAMPSERVER_HOME>\bin\apache\Apache2.2.xx\conf
If it looks like this:
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
then change both:
AllowOverride None
to:
AllowOverride All
I had the same problem and I fixed only by write in my .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
and it's working perfectly.
For some reason when I deploy my API using Restler's API Explorer (a fork of Swagger UI) to production it gives me a general 404 error when I load:
/api/explorer
When I am more explicit and state:
/api/explorer/index.html
It loads the framing for the page but then reports "404 : Not Found ../resources.json" in red text below the header:
I'm fairly certain there's something environmental flaring up as the same files locally work. I also checked the .htaccess file in the /api/explorer directory and it looks right to me:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
Any help would be appreciated.
It turns out all the problems were down to a mod_rewrite problem. I'm still not 100% on WHY this problem showed up in one environment but not others with precisely the same httpd.conf and .htaccess. Oh well, the solution is to be explicit in the rewrite rule about your base url using the RewriteBase directive.
In the API directory I now have the following .htaccess file:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
In the API-Explorer directory I now have the following .htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api/explorer
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
In order to troubleshoot this problem one invaluable tip that I came across is turning on Apache's mod_rewrite logging.
# Adding logging for Rewrites
RewriteLog logs/rewrite.log
RewriteLogLevel 2
Put this in any globally scoped area of httpd.conf; I put it around the entries that were already there about logging but you can also just put it at the end if you like that better. In addition, the basics around rewrite troubleshooting includes (apologies if this basic):
make sure that your httpd.conf has AllowOverride All and Options FollowSymLinks set for the directories you serving Restler out of.
You can put all of the configuration into httpd.conf and avoid .htaccess files altogether (and it's a bit faster that way too) but if you do that remember that httpd.conf has absolute url referencing versus .htaccess's relative.
You can check the ReadMe file on the Restler Github page
https://github.com/Luracast/Restler-API-Explorer#readme
Did you add the 'Luracast\Restler\Resources' class to create resources.json at API Root?
In your own index.php, the addAPIClass section should look like this:
$r = new Restler();
$r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root
// ... your own addApiClass
$r->handle();
It is in the documentation under "Use", but I had trouble figuring this out as well...
Make sure you have cache directory with write permission in your api root