i'm trying to make a codeigniter based website be able to convert index.php?option=test&controller=con1 to /test/con1 using .htaccess i tried multiple examples i found and none seem to work, it goes straight to the home page. any ideas?
i've tried things like
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^\/(.+?)\/(.+?)\/? /index.php/$1/$2 [L]
but doesn't throw any errors or anything.
my current htacces is
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|img|js|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
try put this .htaccess in same directory with your index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Related
I am using FTP to upload a codeigniter website to a server. I have arranged the files in FTP as following (I don't have 10 in reputition):
The index.php finds the system and application folder. But I don't know what to do with the .htaccess file. I have tried various examples from the web and here's an example:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/public_html/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public_html/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ public_html/index.php [L]
This is the first time I use codeigniter and this question is probably stupid (sorry). I'm really thankful for all the help I can get.
I have another .htaccess file now which removes index.php from url:
RewriteEngine On
RewriteBase /example.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
If you want to remove index.php from urls then please use following code in .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Copied from revision 3 of the question
So the problem wasn't the .htaccess! I fixed it by making my
controllers first letter a capital letter.
Can't figure out what I'm doing wrong.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)\.php$ detail.php?name=$1 [NC,QSA,L]
RewriteRule ^(.+)/directory/\.php$ detail2.php?name=$1 [NC,QSA,L]
The first RewriteRule should redirect anything (ending on php like domain.com/product1.php) from the root domain to detail.php (it can not affect things like domain.com/contact.php)
A 2nd RewriteRule should redirect anything from domain.com/directory/product-b1.php to detail2.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /foldernamehere/index.php/$0 [PT,L]
paste this code in your .htaccess file it will resolve your problem
I am new in codeigniter and i am trying to remove index.php from URL in Codeigniter but not able to do this.
I wrote code in my .htaccess file-
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My Apache mod_rewrite is enable.
But still got 404 error when i am trying to access any controller without using index.php.
Please help.
Thanks.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
</IfModule>
Is the code I'm using, it works on every hosting platform I've used it on.
This should help you,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
check this code of htaccess file.
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
you can find your answer refference here
My .htaccess file is not working
moreover can you share your base url with us? as this error may be due to wrong baseurl set.
I am having a tough time to understand how mod_rewrite works.
I have a url like this:
www.example.com/store/index.php?categ=headbands
And I want to make it look like this:
www.example.com/store/headbands
I am trying this, but not working:
RewriteEngine on
RewriteBase /store/
RewriteRule ^index/([^/\.]+)/?$ $1 [L]
And I confirmed the mod_rewrite is activated with a random example I found.
Any suggestions?
Thanks!
Try This one
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/store/(.*)$ /store/index.php?categ=$1 [NC,L]
OR
Put the .htaccess file inside the "store" directory with following code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?categ=$1 [NC,L]
I am doing a project with fetching data from database. I am used URL rewriting method. I was using rewrite method it will redirect to error page
Dynamic url
http://www.sample.com/?cat=kk
The rewritten URL
http:/www.sample.com/kk
the .htaccess file written for this URL rewrite
RewriteEngine On
RewriteRule ^([^/]*)$ /?cat=$1 [L]
The .htaccess file also contain another url rewrite
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /?cat=$1&sub=$2&year=$3&page=$4 [L]
RewriteRule ^([^/]*)/([^/]*)$ /?cat=$1&sub=$2 [L]
RewriteRule ^([^/]*)/([^/]*)$ /?cat=$1&sub=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/$ /?cat=$1&sub=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /?cat=$1&sub=$2&pag=$3 [L]
RewriteRule ^([^/]*)/$ /?cat=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
The problem I am having is that when I access any page, it will redirect to server default error page.
I'm sorry to say that, but your rewriterules are messy.
Always start from the most complex to the simplest one.
And you've forgotten one of the most important directives: QSA. I let you google for this ;)
Maybe what follows still doesn't work, but it's cleaner.
We need log files to know what's happening.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /?cat=$1&sub=$2&year=$3&page=$4 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /?cat=$1&sub=$2&page=$3 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ /?cat=$1&sub=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ /?cat=$1 [QSA,L]