I have a Codeigniter site that works fine on my local XAMPP server, but now I've moved it to shared hosting I get a 403 forbidden error when I click on any link. The homepage displays fine, but any page with a slug produces the 403 error. E.g.
http://xxxxxxxxxxx/~test/
works fine
http://xxxxxxxxxxx/~test/about-us
produces the 403 error.
I saw this question, but my application folder and its subfolders and files already all have permissions of 755.
My Base Url is set to
http://xxxxxxxxxxx/~test/
My .htaccess looks like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt|static)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
EDIT: If it makes a difference, I should say that I modified the core router.php (I know it's better to create my own MY_router.php, but anyway) to allow hyphens in the URL:
$segments = $this->_validate_request(str_replace('-','_',$segments));
but I tried changing it back to
$segments = $this->_validate_request($segments);
and it made no difference.
EDIT 2:
Another update. It works with URLs like this:
http://xxxxxxxxxx/~test/about-us/consultancy
just not with this
http://xxxxxxxxxx/~test/about-us
although this does work:
http://xxxxxxxxxx/~test/about-us/
Related
This seems so basic, and there's a plethora of questions regarding .htaccess online, but after two days of research, I still can't make mine work the way I want.
What I want is:
Force https on all requests
Always use the "www" version of the url.
Work on multiple domains (but not redirect them all to a master domain). All my domains point to the same folder (so they'd use the same codebase), and in its root is the .htaccess file.
Remove the "index.php" part of the url, to make it human and SEO friendly.
This is what I have so far:
Start with the basic .htaccess code for CodeIgniter, as shown in the userguide:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
Originally, the last line had the [L] flag, but I omitted it, so it will continue to the following rules.
(Am I correct in assuming that it takes the url output in the previous RewriteRule, and perform the following matches on it?)
# for non www urls, add www and force https:
RewriteCond %{HTTP_HOST}(.*) !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R,L]
# for www urls, just force https:
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
The above code is achieving tasks 1-3 of my list above, but the index.php is still showing in the address bar.
How do I remove it?
Well, I (partially) gave up on .htaccess, and solved my problem in a different way:
I'm now using CodeIgniter hook to deal with forcing https, and leave htaccess to deal only with forcing www and removing index.php
So I removed the last line (RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]), and added an ssl hook to my application, and all is working now.
The hook function, in case anyone is interested, is this:
function force_ssl()
{
if ($_SERVER['HTTP_HOST']!='localhost' && $_SERVER['HTTP_HOST']!='10.0.2.2')
{
$CI =& get_instance();
$CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);
if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string());
}
}
codeigniter page not found showing but working fine in local server.
I had uploaded codeigniter file of one basic simple page on live server but there it is showing no page found and same file it is working on local server.
In that I had
mine.php ---- controller
index.php --- view
I loaded in routes default controller - mine in config base url- domain.com removed index.php also
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
can I know please why it is showing page not found, might be some routing issue but I had loaded default controller also. Please help out on this
First of all start error logging properly so you can see the actuall error.
Change your file name's first letter capital. This is mendetory as explained here ci3 manual - controllers. It says class name as well as file name must start with capital. ( If your Dev machine is windows then it will not show errors if you don't follow this rule. Because window's file system is case insensitive. But on your server it is linux.so it will show error)
If you still don't get it working then try access the url with index.php in it. Temporaryly disable .htaccess .If you get it working then may be you have problem in . htaccess. Try the following link to properly remove index.php from your url. Expression engine forum .This htaccess worked for me on all different server I have used.
add this in .htaccess file
<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>
I have some problem with my url.
I had copied my website script to another website of mine, and changed the url.
original permalink : (A)
domain.tld/path1/path2/post_title.html
I had changed it to the (B)
domain.tld/path1/post-title.html<br/>
but the problem is. When i open B, there is error
404 Page Not Found
The page you requested was not found.
and i tried to open
domain.tld/path1/path2/post-title.html working fine.
Please help me to solve this issues.
Below are my .htaccess
http://prntscr.com/2928f1
You need to change the base url in the config file that is in app/config/config.php with the new site path like
$config['base_url'] = 'domain.tld/path1/path2/';
And make sure that you has using same db orelse you also need to change the DB config also.And dont put the new folder that includes path2 in the old path path1.If iam not wrong you are putting the new one in the older path.create a new folder with domain.tld/path2/
No worry any more about base url.
In your application/config/config.php, change $config['base_url']='' to
$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
.htaccess
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond {REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [l,QSA]
I have a simple file mydomain.com/business_nottingham.html
and i want to re-write that to an SEO friendly URL, eg mydomain.com/business-nottingham/
I've googled all the examples but they seem to be designed for either CMSes or PHP scripts.
Is there a simple .htaccess re-write example available that allows me to do something very simple as above?
Edit: I managed to find the following code finally
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
However, it's still not quite working. If i enter the tidy URL, i get re-directed to a 404 page, but putting in the exact .html file name gets me to the right file but doesnt present me with a clean url.
I've tried various combinations of the above by reading various articles and tutorials but for some reason it doesn't seem to work for me.
You want to redirect only when the actual request is for an .html file, then you want to internally rewrite to the html file. The way URLs resolve is the browser shows where it thinks it's going (URL in the address bar), then the request is made to the web server. If the webserver (where the htaccess file is) wants to change what's in the browser's URL address bar, it needs to tell the browser to literally load an entirely different URL. The browser will then request the new URL. Then the server must internally rewrite that URL back to where the actual resource is (the first URL), but the browser doesn't see this happen.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.html
RewriteRule ^ /%2/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.html -f
RewriteRule ^ /%1.html [L]
I just transferred my local web app to my server, and now I'm getting this error:
Parse error: syntax error, unexpected
T_OBJECT_OPERATOR in
/nfs/c05/h01/mnt/71658/domains/ergo-metric.com/html/application/libraries/Survey_form_processing.php
on line 172
This is odd because it works locally! I changed my db settings to the production server, and my base_url is correct.
Any ideas what this could be?! I'm a little worried b/c this is a live site!
I would start with your php config file, check what is enabled on your end and what is enabled on the other end. but first check your config file and look for rewrite short open tags switch it to true. these are very basic but you didn't give a whole lot of information, maybe post a few lines of code before and after 172 let me see what is going on there. also if you are using htaccess files and are still using the default CI example i would switch it to this works like a charm: this is a universal htaccess file no matter your setup you dont have to change it promise you that the best thing since sliced bread.
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
i am going to be on for a while if you reply maybe we can get this worked out for you two heads are better than one thing you know