how to remove index.php file from url in codeigniter? - php

I am trying to remove index.php from my url, but I am confused which code i used in .htaccess file and what changes I have to make on related file in codeigniter .

Just use this .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Taken from here

Add just this line to your htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>

If you're using IIS, try importing these rules to your web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">*
<add input="{URL}" pattern="^system.*" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.php?/{R:1}" appendQueryString="false" />
</rule>
<rule name="Rule 2" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{URL}" pattern="^application.*" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="/index.php?/{R:1}" appendQueryString="false" />
</rule>
<rule name="Rule 3" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?/{R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>

Related

PHP MVC: htaccess converted to web.config gives me http error 404

I am installed my project done in a PHP MVC framework on a Windows server, but I am having difficulty in making the part of the URLs work.
There are two htaccess, one out of the app and public folders, and one within the public folder.
The first one:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
I converted to web.config using a tool made available by IIS, and it is working.
But the second htaccess does not work.
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
Converted:
<configuration>
<system.webServer>
<rewrite>
<!--This directive was not converted because it is not supported by IIS: RewriteBase /.-->
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/public/index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
Currently giving error 500, internal server error.

How to convert conditions in .htaccess file to web.config

I have this .htaccess file:
RewriteCond %{REQUEST_URI} !/admin/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^(.*)$ rewrite.php
How do I rewrite this in a web.config file?
Try this
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{URL}" pattern="/admin/" ignoreCase="false" negate="true" />
<add input="{THE_REQUEST}" pattern="^[A-Z]{3,}\s([^.]+)\.php" />
</conditions>
<action type="Rewrite" url="rewrite.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

how to convert htaccess to web.config

i'm working on a website project, and i have to install the website on the client's server. He has a Godaddy windows account, which doesn't accepts .htaccess files, it uses web.config instead. I dont really know how to write web.config, an i'm in hurry also. I've tried to convert my htaccess with some online converters but of course it doesn't works also. Can you help me out please?
my htaccess:
Options -Multiviews
RewriteEngine On
# Allow any files or directories that exist to be displayed directly
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME] !-d
RewriteCond %{REQUEST_FILENAME] !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
What the generator generates from it as web.config:
<rule name="rule 1w" stopProcessing="true">
<match url="^" />
<action type="Rewrite" url="/-" />
</rule>
<rule name="rule 2w" stopProcessing="true">
<match url="^(.+)$" />
<action type="Rewrite" url="/index.php?url={R:1}" appendQueryString="true"/>
</rule>
Aaand i fixed it in 2 minutes after i posted this question!
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Convert HTACCESS to WEB.CONFIG IIS7

I have this .htaccess file. When importing it to IIS via URL Rewrite module it is giving errors. Can someone please help convert it to webconfig.
Thanks in advance
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?action=$1 [NC,L]
</IfModule>
The third condition "is symbolic link" is not supported in IIS rewrite module. If there's no symbolic link implemented, the following rule will be the equivalent:
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.+)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?action={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>

htaccess is not working on iis

how to convert .htaccess to web.config.
I just come to know that I need to use web.config instead of htaccess. Please find my htaccess below
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
how i can convert it into web.config ?
copy paste below code in your web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Categories