htaccess not working on my VPS with cpanel - .htaccess

I have a website which was on a VPS with directadmin Control Panel, but I have just moved to another VPS with Cpanel. It used to work when it wan on the old VPS but in the new one I can’t make it work..!!
My script is CodeIgniter script and in this script this url:
www.mydomain.com/index.php/news
should be converted to:
www.mydomain.com/news
But after using htaccess, I can open the main page (which is index.php) greatly but when I want to go to www.mydomain.com/news (this should be defined as www.mydomain.com/index.php/news by htacces ) it shows me the main page. I have installed CodeIgniter (the framework I am using for my script) in the public_html folder (which is under home/user).
I have full admin access to my VPS, WHM/Cpanel and I can make any changes.
this is the .htaccess that was working for me in my old VPS:
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
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 have just found that by converting this line:
RewriteRule ^(.*)$ index.php/$1 [L]
to this one:
RewriteRule ^(.*)$ index.php/$1 [R]
means changing flag [L] to [R], it works, but it just converts www.domain.com/news to www.domain.com/index.php/news and shows in the addressbar and this not what I want.
Do you have any solution?! Should I change any configuration on Cpanel?!

Try this one:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|images|css|js|favicon\.ico|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Hope it works on your CodeIgniter install, I had the same problem and this solved it.

Related

Laravel throwing 404 on images/css/js

Laravel is throwing a 404 error on my images, css and javascript files which are located in /mysite/public. I've set /mysite/public as the site's root folder and all my assets are located in there.
I did a google search on this error but they all gave the same solution i.e {{asset('css/style.css')}}. I already have my links setup like this so I don't think this is the problem.
I think the error has something to do with my Rewrite rules but I just can't figure our what it is.
My site's .htaccess file is:
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.my-site.com/$1 [R,L]
</IfModule>
If I delete the first RewriteRule, my css loads fine but pages other that the homepage will start throwing a 404 error. If I put it back, other page work fine but css, js and image file stop loadings.
Your first rule essentially says "regardless of what the URL is, load index.php". This means it will never load your assets, which are physical folders, as it will just load index.php instead. For example, if you tried to load css/image.png it will just load index.php.
If you remove it, your actual folders will load, but other URLs aren't re-written to index.php, which is why it will break.
You should use the .htaccess provided to you by Laravel. This should be your .htaccess file in the public/ folder (as per the Laravel Github repository)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
public/.htaccess
If the public folder is not the root on your server, you'll also need to have this in an additional .htaccess (in the folder above public)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
/.htaccess
add this rule to keep assets from being routed to the router
RewriteEngine On
# Don't rewrite for css/js/img assets
RewriteRule ^assets/.* - [L]
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.my-site.com/$1 [R,L]

How to Upload my CodeIgniter Project in 000webhost

I created one CodeIgniter project and it is working fine in my localhost,i removed index.php in that project and directly i am accessing the default controller /localhost/code2/.... everything is working fine...
what i want is,i want to upload same in 000webhost,i copied all the ci file and paste in public_html folder in 000webhost but it show 404error.
//.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
helpme to solve this...
Remove every thing from .htaccess that resolved my issue . and make sure that your codeigniter file should be in That folder which is link to your domain
Try to change this code:
RewriteRule ^(.*)$ index.php?/$1 [L]
to :
RewriteRule ^(.*)$ ./index.php?/$1 [L]

when removing index.php from url ( codeigniter ) .htaccess Prevent the files from the display

I'm using codeigniter, and I tried to remove index.php from url by creating .htaccess file
and it contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
this way is working will at xampp server.
but when I uploaded the site, unfortunately there was a problem appeared:
I have a folder called files and it content sub folders: images, css, js, swf, upload.
and every file at those folders can't view, and the browser said there the file not found.
any help ploese.
Just make sure you exclude those too:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|swf|upload)
RewriteRule ^(.*)$ /index.php/$1 [L]
This is my .htaccess file. My understanding is that for any file or directory which has access attempted and doesn't exist, it will forward onto Codeigniter.
Anything which does exist will work fine and will not require individual exclusion. This will save time and hassel each time you add a new directory or folder as it wont require you to edit this file.
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Works for us, but my understanding may well be incorrect. Hope it helps
try this one which i think will solve your problem ..
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
you have to tell your server not to handle those directories over to index.php and the line which work for this is :
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
Here is my .htaccess file - which should work for you:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(files|css|js|swfimages|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml|maintenance\.html)
# but rewrite everything else
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.
ErrorDocument 404 index.php
</IfModule>
thank you. this worked fine:
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I have another website and next index.php I have a folder called files, and this one content alot of folders should I have to put all names of them and names of sub-directories in them?

How to Remove index.php from URL in PHP

I want to remove index.php from url but so far i couldn't succeed it. I'm using Wamp server on my local and Apache on remote server..
In local root directory, my project files are located in a subfolder like
www/project/index.php
I can access web pages like
localhost/project/index.php/home
localhost/project/index.php/messages/?mId=3
I just want to access it like
localhost/project/home
localhost/project/messages/?mId=3
I already tried some .htaccess rewrite rule but couldnt make it.
Here's how you need to organize:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>
And then you will have everything as you need.
You will want to use url rewriting with a .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Put a .htaccess with this content in each subfolder.

moved to dedicated virtual server, having trouble with .htaccess and permissions

Working with cakePHP
My index.php is in www.domain.com/httpdocs/sub/app/webroot
Previously, on shared hosting I just replaced "domain.com/" with "domain.com/app+core directories" (without httpdocs/ or sub/)
I've moved to media temple dedicated virtual server and am hitting a 403 forbidden error:
"You don't have permission to access /sub/ on this server."
Permission is set to 755 for sub/ directory
In domain.com/sub/app -> .htaccess file:
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /sub/app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
In domain.com/sub/app/webroot -> .htaccess file:
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteBase /sub/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
I've tried:
Right now httpdocs/ contains blank index.html and simple redirect:
Redirect /index.html http://domain.com/sub/
Creating another .htaccess file for /sub, but that seemed to confound things further.
I'm on media temple, followed this article: http://wiki.mediatemple.net/w/403_Forbidden_error
Thanks
Noticed you were having some issues with your (dv). We just wanted to let you know that we are here to help you with any problems that you may have. If you keep running into these errors, please open up a Support Request so we can help you out.

Resources