I want to do routing in code-igniter and i have done the below steps also
but it is not working.I have done all the required settings also but then also
its not working.Please let me know is i am missing any thing or not.
Step 1
Add This in .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Step 2:
Remove index.php in codeigniter config
$config['index_page'] = '';
Step 3
Add this in route.php
$route['Viewsignup'] = 'Login/index/Viewsignup';
My url is like that:
http://localhost/machinetest/index.php/Login/Viewsignup
I want this url:
http://localhost/machinetest/index.php/Viewsignup
Please help me,
Thanks in Advance
.htaccess should not be issue here. Try this
$route['Viewsignup'] = 'Login/Viewsignup';
This will take you into Login controller's Viewsignup method when your URL looks like http://localhost/machinetest/index.php/Viewsignup
And for removing index.php from URL just update your .htaccess with following
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Now http://localhost/machinetest/Viewsignup URL will work too
On some servers, Apache is configured to ignore some or all directives in .htaccess files. This is for security reasons. The AllowOverride directive controls which features will be allowed in .htaccess files. For example AllowOverride None can turn off htaccess files for a folder and its subfolders.
Check your Apache configuration file for which AllowOverride directive is applied to the directory containing your problem htaccess file.
If you’re not sure which configuration file to look in, start with the main Apache configuration file httpd.conf or apache2.conf. If your website is configured in a file included by httpd.conf (e.g. a virtual hosts configuration file), you will need to look in that file. See Location of httpd.conf on CentOS, Ubuntu, Mac and others to locate your httpd.conf.
To enable using a .htaccess file, change AllowOverride None to AllowOverride All.
For example, for a CentOS 5.3 server, I needed to change the AllowOverride setting in the file /etc/httpd/conf.d/virtualhosts.conf.
httpd.conf before:
Options FollowSymLinks
AllowOverride None
httpd.conf after:
Options FollowSymLinks
AllowOverride All
Be aware that enabling htaccess files has security implications, as htaccess files override your Apache configuration. For example, if your site provides uploads, a hacker could potentially upload a .htaccess file to your server and use it to gain access to your server. There are options to AllowOverride that restrict the directives that will be used from a .htaccess file. See the documentation for AllowOverride.
refer http://smartwebdeveloper.com/apache/htaccess-problems
Related
In my phpinfo() command it shows mod_rewrite is enabled, yet i'm still getting apache's default not found page instead of my own "404" page. Here is my .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ test_modrw.php
Here is the section in phpinfo that shows mod_rewrite is enabled:
EDIT
Thanks Agama. But still one issue, I can still directly access files in the root. For example:
example.com/test_file.php
Can still be accessed instead of the .htaccess routing everything to index.php which is also in the root. Here is my .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
EDIT
Can you guys upvote this question as well as others of mine? S.O. has banned me because they think my questions are of low-quality because of little upvotes.
Please change the conf as below to allow the access in your /etc/apache2/sites-available or /etc/httpd/conf.d/
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
A better answer would be to check that AllowOverride is set to all and not none in the necessary <Directory> directive (find the one that corresponds to files you serve). Just be conscious it will enable your .htaccess files to override a lot of options from the config.
Only do that if you know what you are doing (aka, don't do that on a server where other users can upload files as they might be able to change some options that you don't want changed). If you're the only one hosting sites on this server, all good.
If you're conscious about security and/or what other users can do, for the purpose of rewriting things, you could just change AllowOverride none to AllowOverride FileInfo Options
FileInfo will enable the rewrite rules and Options will enable what follows.
Then, in your .htaccess file, just add at the beginning:
Options +FollowSymLinks -MultiViews
By doing that, you'll ensure the FollowSymLinks option is enabled, and MultiViews is disabled (as pointed out in a comment, it will cause issues with rewrites rules in certain scenario - typically, when you have double extensions like .en.php, .fr.php and Multiviews kicks in), no matter what the default Apache config is.
This is far better to control that on a folder/vhost basis than on the server level.
I would also highly recommend to disable Indexes altogether from the main config file as it's an open door to list unwanted files (basically, it shows the content of any folder that doesn't have an index file).
So I have a server running on Digital Ocean. I'm trying to run Anchor CMS on it. So this is what the URL should look like http://colourity.com/posts/hello-world. But that doesn't seem to work. When I try http://colourity.com/index.php/posts/hello-world, all works fine. But the problem here is that I'm using .htaccess to correct this, here's what I have,
Options -indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
That should of gotten rid of the index.php, additionally mod_rewrite is enabled. I've also restarted the server to see if that makes a difference, but it hasn't. Any ideas?
AllowOverride All must be included in the Apache configuration so that .htaccess rules can overwrite your configuration. From the documentation:
When the server finds an .htaccess file (as specified by AccessFileName) it needs to know which directives declared in that file can override earlier configuration directives.
When this directive is set to None, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.
When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files.
It's default value is All, but some template configuration files may have it manually set as None. Also note, that this syntax is only available in <Directory /> sections.
I have rather basic htaccess document that forwards the request to be handled by a php file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /controller.php [L]
This works fine when browsing normally. However, if I switch to using https it no longer will listen to anything in the htaccess document.
I am just wondering is this a server configuration issue and what can be done about it?
You should ensure that content is loaded from the same directory as for non-ssl version. In some configuration for example default for http is public_html directory and for https private_html directory. .htaccess should work without any problem if content is loaded from the same directory in both cases
Found the issue!
It was a httpd.conf issue with the AllowOverride being set to None instead of All. With this set to None it wouldn't allow htaccess to work over SSL port
Found from: https://www.centos.org/forums/viewtopic.php?t=31351
"Open the Apache configuration file located at /etc/httpd/conf/httpd.conf
Change AllowOverride None to AllowOverride All inside the DocumentRoot Directory Directive, normally "
i am new in php & codeigniter.i am working on a project which was running in a server abcd.comand i am using htaccess code like this
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
now my project has been moved to another server 192.000.000.000.i can access the login page, when the user is logged in session is getting set and it is redirecting to 192.000.000.000/myproject/user and here i am getting 404 error
i have been set base_url in config.php is like this
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['index_page'] = '';
my WINSCP Project structure
old one : /home/my_org/public_html/prjFolder
new one : /var/www/html/prjFolder
my .htaccess file like this
system/
application/
user_guide/
index.php
.htaccess
if anyone find solution please help me..
You mention that your project was moved to another server. Did you check if the AllowOverride directive (assuming you're using Apache as your web server) is set in your virtual host? If this is disabled, Apache will simply ignore your .htaccess file. A quick test is putting some nonsense in your .htaccess file that would certainly generate an error. If you don't get a server error, your .htaccess file is being ignored.
Link:http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
Another cause could be that the mod_rewrite module is not enabled (again, assuming you're using Apache). You don't say if your pasted .htaccess code is your complete .htaccess file, so I don't know if it's checking if that module exists. A simple test to check if this is the cause, is trying the resulting url of the rewrite: 192.000.000.000/index.php/myproject/user
Link:http://httpd.apache.org/docs/current/mod/mod_rewrite.html
I am assuming you don't have any errors in your .htaccess file, since you seem to say that it worked fine before the move.
I think your problem in the destination pointed by your rewrite rule
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
If you are accessing your project through the URL
192.000.000.000/myproject/user
The rewrite rule will change this to
192.000.000.000/index.php/myproject/user
You need to modify your rewrite rule to exclude myproject/user from the url to be pass to index.php or you can just remove the .htaccess if this is only a dev machine, the reason my we hide the index.php is so that the url will look pretty. Having it on the dev environment wouldn't hurt at all.
I find the solution , It is the problem of apache rewrite_module. I changed my httpd.conf file and now its working perfect.
Change AllowOverride None to AllowOverride All
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and Restart the Apache daemon using putty # service httpd restart
Reference Url : - http://dev.antoinesolutions.com/apache-server/mod_rewrite
I'm on a win8 machine running XAMPP. I have a virtual host directory set up with a .htaccess file. I have been researching how to rewrite urls and I found the RewriteEngine module. In my httpd.conf apache file, the module was already enabled:
LoadModule rewrite_module modules/mod_rewrite.so
It seems like the next step was to update my .htaccess file like so:
php_value register_globals off
DirectoryIndex default.php index.php
ErrorDocument 404 /filenotfound.html
RewriteEngine On
RewriteBase /
RewriteRule ^Home$ Default.php [L]
RewriteRule ^AboutMe$ About.php [L]
RewriteRule ^Work$ Work.php [L]
RewriteRule ^Blog//Categories$ Blog/Categories.php [L]
RewriteRule ^Blog//([^/.]+)/?$ Blog/Posts.php?val=$1 [L]
I have followed a couple SO questions (config and rewriting w/ params), but am unable to get even the easiest rewrites to work. I have restarted apache a couple of times with no results.
While I'm here, this is my folder structure boiled down to everything relevant:
root
.htaccess
Blog
AuthorPanel.php
Categories.php
Post.php
Posts.php
Default.php
About.php
Work.php
And these are the rewrites I am looking to achieve (I have already tried most of them):
site.com/Default.php => site.com/Home
site.com/About.php => site.com/AboutMe
site.com/Blog/Categories.php => site.com/Blog/Categories
site.com/Blog/Posts.php?id=3&val=Android => site.com/Blog/Android
site.com//Blog/Post.php?id=4&title=Working+with+ActionBar => site.com/Blog/Working-with-ActionBar
Update 1 In httpd-vhosts.conf I even tried using the RewriteEngine on and rewrite rules, with no luck either:
<VirtualHost *>
DocumentRoot "C:/Users/ben/Documents/PHP/benWIT"
ServerName benWIT.local
<Directory "C:/Users/ben/Documents/PHP/benWIT">
RewriteEngine on
Order allow,deny
AllowOverride all
Allow from all
Require all granted
RewriteRule ^Home$ Default.php [L]
RewriteRule ^AboutMe$ About.php [L]
RewriteRule ^Work$ Work.php [L]
</Directory>
</VirtualHost>
Since you are using htaccess then you will need to make sure AllowOverride is set to All in your httpd.conf file:
AllowOverride All
This will allow you to use htaccess files. Having said that, as a general rule you don't want to use htaccess files or enable AllowOverride if you have access to the apache config files simply because it will use more resources to search the directory and find the htaccess files etc. Placing the changes into the httpd.conf file or conf.d/example_host.conf is much better.
One other note, mod_rewrite is over used and is really overkill for most purposes. I would advice you use mod_alias (see http://httpd.apache.org/docs/2.2/mod/mod_alias.html) instead. I should point out this can only be use in server configs or virtual hosts, so it will not work in a htaccess file. But it should be given preference should you have the choice between the two.
Alias /home /default.php
Alias /aboutme /about.php
Alias /work /work.php
AliasMatch /blog//([^/.]+)/? /blog/posts.php?val=$1
.. and so on.
Here is a good read on when not to use mod_rewrite:
http://httpd.apache.org/docs/2.2/rewrite/avoid.html