I have codeigniter app in home directory. Sym link created in /var/www/html. I made changes to incldue .htaccess file in application folder to remove index.php in URL. The below link works fine.
http://mydomain.net/dms/welcome
That is, default method of controller works fine. But when I have method 'test' in welcome controller, the following link results in HTTP 404 webpage not found error.
http://mydomain.net/dms/welcome/test
Code igniter 2.1.1 directory:
dms
application
system
index.php
.htaccess
Config.php
$config['base_url'] = '';
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
Config file httpd.conf
Alias /dms/ "/var/www/html/dms/"
<Directory "/var/www/html/dms">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Sym links
ls -l /var/www/html
dms -> /home/user1/dms
.htaccess file
Options +FollowSymLinks -Indexes
Options -MultiViews
RewriteEngine on
<IfModule mod_php5.c>
RewriteRule ^([^/]*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^([^/]*)$ index.php?/$1 [L]
</IfModule>
I also tried with the following 2 Rewrite rules in place of above rules in .htaccess file.
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [L]
But contoller method cant be accessed without using index.php in URL. Having spent much time in this, I think it is something to do with Rewrite rules. Could some one guide me on this.
Please, test this configuration for .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|.*\.css|.*\.js)
RewriteRule ^(.*)$ /angular1/index.php/$1 [L]
Replace "angular1" by your correct path.
Related
On production I have domain http://xxxx.com.
In root folder I added .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
</IfModule>
And when I type in the browser: http://xxxx.com it works.
The same .htaccess file I have on my machine. I use XAMPP. And it doesn't work. When I type:
http://localhost:8082/myfolder
I get 404. When I type:
http://localhost:8082/myfolder/public
It works.
What is the difference between url in my hosting and on my local machine?
For the first answer:
this is a screen, maybe I'm doing something wrong (.htaccess is in the root folder), maybe .htaccess in the public folder is wrong:
This should work for you:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteRule !^public/ public%{REQUEST_URI} [L,NC]
</IfModule>
The problem with your rule is that you're checking this condition:
RewriteCond %{REQUEST_URI} !^/public/
Which actually checks for URI /public from web root however you have your site inside a subfolder locally. Here RewriteRule !^public/ will check if public/ is not there at the start after the current directory context, which will work the same in site root as well in a subdirectory.
Similarly for rewriting also make sure you don't use / before public/ to allow it to use a relative path.
All of my .htaccess in codeigniter like this
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
But all tutorial .htaccess are like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I need help to remove index.php url in codeigniter.
Why should I replace all code .htaccess like tutorial said ?
Should you replace all code .htaccess like tutorial said ?
Yes! just in the root directory of your CodeIgniter project.
Why?
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
The CodeIgniter documentation says that by the rules given in .htaccess file, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.
without these rules, for example, you'll have to access your login page like this
http://yourdomain.com/index.php/<controllerName>/login
with the rules in .htaccess file it's
http://yourdomain.com/<controllerName>/login
I just moved old site of my client to some test server.
The site is on PyroCMS.
I've changed database settings in aplication/config/database.php and changed base_url in aplication/config/config.php to my test site URL.
Unfortunatly site is giving me 500 error and I don't have any error logs to see what else is to change.
Where I have to do changes to site run?
My .htaccess looks like this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /wherever/pyro/is
# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(application\/cache|codeigniter|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I use PyroCMS for almost all my clients and the same issue is in the default .htaccess file.
Try to remove:
Options +FollowSymLinks
And try to add:
Options +symlinksifownermatch -Indexes
Options -MultiViews
Many hosting disable +FollowSymLinks for security reason.
Make sure to set 775 permission to:
system/cms/cache
system/cms/logs
addons
uploads
assets
Also make sure to set your env to PYRO_DEVELOPMENT to see all the errors in this debug phase.
I went through many resources here and elsewhere in net but couldnt seem to make it work.
I have codeigniter app in home directory. Sym link craeated in /var/www/html.
The below link works fine.
http://mydomain.net/dms/index.php/welcome
However without index.php ,I want the following link to work
http://mydomain.net/dms/welcome
Code igniter 2.1.1 directory:
dms
application
system
index.php
.htaccess
Config.php
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
routes.php
$route['default_controller'] = "welcome";
Config file httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
Alias /dms/ "/var/www/html/dms/"
<Directory "/var/www/html/dms">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
sym links
ls -l /var/www/html
dms -> /home/user1/dms
.htaccess file :
RewriteEngine On
# enable symbolic links
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+) index.php [L]
I tried keeping .htaccess file in CI folder folder /home/user1/dms and later in /var/www/html
Both didnt work.
I am getting error (in http error log)
"File does not exist: /var/www/html/dms/welcome"
Please help.
I use this .htaccess and it works for me, try:
<IfModule mod_rewrite.c>
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
# disable the Apache MultiViews directive if it is enabled on the server. It plays havoc with URL rewriting
Options -MultiViews
RewriteEngine on
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
I have urls that all contain /main/ in the url as it is my main controller.
I'd like to get rid of it.
I understood in the User Guide that the routing class will only re-route my URL, not hide a part of it (it is segment 1 according to their docuementation).
Thus, I've found this:
$route['(:any)'] = "auth/$1";
But I have 404 errors (That's the only modification I made to routing.php)
I believe I'll have to do it in the .htaccess, but I don't know what should be the syntaxe for that. For now, my .htaccess is this one:
<IfModule mod_rewrite.c>
SetEnv MAGIC_QUOTES 0
SetEnv PHP_VER 5
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymlinks -MultiViews
Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine On
DirectoryIndex index.php
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I am using several controllers and my links are similar to this one :
Thanks
Try this:
$route['blog'] = 'blog'; // seem stupid but otherwise the (:any) route below will send it to main
$route['blog/(:any)'] = 'blog/$1'; // to have blog cotroller work
$route['blog/(:any)/(:any)'] = 'blog/$1/$2';
// repeat for other controllers
$route['(:any)'] = "main/$1";
$route['(:any)/(:any)'] = "main/$1/$2"; // if you use other uri parameter
$route['default_controller'] = 'main'; // to have your main page work...
And put before this directive all calls to other controller as this will prevent all other controller calls.