htaccess syntax on CMS CodeIgniter - .htaccess

I am currently creating a CMS using CI. I have the following htaccess:
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
this works fine for me but when I try to access mywebsite.com/admin/user/login the page is not found. What can I do about it?

Related

Statically served NextJS website is adding a trailing slash on page refresh

I have a NextJS website statically served on an apache server and using an .htaccess file to setup the routing rules etc. This files looks like this
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/]+)/$ $1.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [L,R=301]
</IfModule>
The problem I'm facing:
My internal links look like example.com/page-1, so when I redirect from example.com to example.com/page-1 everything is working well.
But when I target this page directly from it's URL or reload the page the server is adding a extra trailing slash to the URL. e.g. example.com/page-1/
This causes duplicate content within search engines /
What I'm looking for:
I'm looking for a solution in my .htaccess that prevents the server from adding a trailing slash on reloading the page. But URL's like example.com/about/page-1 should keep working.
I found a solution for my own problem. The problem was causes because I copied this .htaccess from an old React project where it was supporting the react-router.
Within my NextJS project I only had to remove the .html extension inside the .htaccess file. See example below:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>

issue in removing index.php in codeigniter 3 while using redirect method

in codeigniter 3.1.3, while i'm using redirect('Admin','refresh') method from Login controller, in url it shows localhost/rsufadmin/index.php/Admin.... i have a htaccess file which contains
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
if i manually type localhost/rsufadmin/Admin , Admin controller work just fine... but i have to go to other controllers from a controller. So, how can i remove this index.php part from url??
i have some screenshot below to make it understand easier... while using redirect method from controller,.. while manually entering url
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|images|asset|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Htaccess file not working on phpmyadmin.ovh.net

I use codeigniter for my website buliding, after following the process to remove index.php file, everything work properly on localhost but when i host my site on phpmyadmin.ovh.net it's not working anymore, i can't reach any link. Can somebody help me ?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

url not working with browser other than chrome, htaccess file error

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|js|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
I have written this .htaccess file when I access localhost/myProject/home in Chrome this works fine but in other browsers it show page not found error
Most likely you need Options +FollowSymLinks. And for more htaccess for codeigniter click on link and download zip At David Connelly's Website. They have about 5 different ones that you could try in zip, no doubt one of them will work. http://www.insiderclub.org/downloads
The one I use below works fine in all browsers for codeigniter. Make sure when you use this or any other htaccess, that you place your domain in base url at config/config.php and then remove the index.php from config/config.php
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

codeigniter htaccess with multiple applications

I am using codeigniter. I have front end application and backend application like
/system/
/application/
/front/
/admin/
index.php
admin.php
.htaccess
I want my url like http://example.com/news/article1 (for site)
http://example.com/news/admin (for admin)
In .htaccess I have written
RewriteEngine On
# If the user types just "admin".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin$ admin\.php [L,QSA]
# If the user enter in any admin section, like "admin/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin\/(.*)$ admin\.php/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
the front end is working fine but when I enter mydomain.com/admin it is throwing 404 not found error. Please help me.
Thanks and regards
I'm not that good with .htaccess, but from the CI website, you can use this for your .htaccess rule
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and then use routes to rewrite your urls. Much easier than trying to do it in .htaccess files

Resources