I'm having an issue with CodeIgniter and htaccess.
When I access to my website in http or in localhost, I can access to mysite.ext/controller/view , like admin/login, for example.
But when I access to my website with HTTPS before, it's sending a 404 error, so I have to write mysite.ext/index.php/controller/view, and it works.
The problem is I don't want the index.php and when I try solutions I found on the internet, it removes index.php sometime, but I can only access to the /index/ controller, not the admin and the other ones.
I tried this solution here :
codeigniter + not index.php with https
It removes the index.php, which is the bootstrap, and the controller/view index/firstpage works, but not the other controllers.
PS : the HTTPS URL is different than the HTTP URL. HTTP URL takes to the server, but the HTTPS is provided by my hoster (so, https:// ovh....blabla../mywebsite/)
I would like to understand why it's not working and find how to correct it.
There is nothing specailly do configuration for codeIgniter setup in https url. First you remove $config['base_url] from your config file and put ''(blank) in your $config['index'] attribute ..
you can set your .htaccess file like..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Above code is remove index.php from url.
Related
Try to set 404 page not found error page by htaccess.
Issue is if we are searching for
https://www.rsseosolution.com/suraj.html ... Its redirect perfect to 404.php.
But if we are searching for
https://www.rsseosolution.com/suraj.php ... Its not redirecting to 404.php and giving showing simple text message "File not found.".
In short problem is if extension is not php then its redirecting fine but if .php then its showing File not found.
ErrorDocument 404 https://www.rsseosolution.com/404.php
Options +FollowSymLinks
RewriteEngine on
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule seo-package-(.*)-n-(.*)\.php$ seo-package-detail.php?id=$1&name=$2 [NC,L]
RewriteRule case-studies/(.*)-(.*)\.php$ case-studies.php?project=$1&id=$2 [NC,L]
RewriteRule tutorial/(.*)-(.*)\.php$ tutorial.php?topic=$1&id=$2 [NC,L]
RewriteRule blog-page-(.*)\.php$ blog.php?page=$1 [NC,L]
RewriteRule seo-tutorial-(.*)\.php$ seo-tutorial.php?page=$1 [NC,L]
RewriteRule frequently-ask-question-faq-(.*)\.php$ frequently-ask-question-faq.php?page=$1 [NC,L]
What i am looking for is ....... redirect all not found or wrong URL to 404.php.
What i am missing here.
I think because we are rewriting some URLs with .php extension from htaccess and thats why for PHP its saying file not found but for other its redirecting perfectly to 404.php.
Is there any ways to set 404.php for all not found pages and URL without change any extension (.php) of previous written file by htaccess.
The problem is not to do with your current directives in .htaccess.
The problem is mostly likely due to your server config and the way PHP is implemented on your server. If requests for .php files are proxied to a backend server for processing as is often the case with FastCGI type configs then this 404 Not Found message is likely coming from the backend server and not your Apache server.
Ordinarily, you would solve this with the ProxyErrorOverride directive in the reverse proxy config:
ProxyErrorOverride On
If you don't have access to the main server config then you may be able to trigger the 404 early using mod_rewrite in .htaccess, before the request is sent to the proxy server.
For example, before your existing mod_rewrite directives:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.php$ - [R=404]
However, this is strictly a "workaround", if you have access to the server config then using ProxyErrorOverride (as mentioned above) is preferable.
Aside:
ErrorDocument 404 https://www.rsseosolution.com/404.php
By specifying an absolute URL in the ErrorDocument directive this triggers an external (302) redirect for the error document (an additional request), which is generally undesirable (and you need to manually set the 404 response code). It is far better to issue the error document as an internal subrequest instead:
ErrorDocument 404 /404.php
A Slim (PHP microframework) app was developed. It works in localhost, but gets an error 500 in production. Here are the details:
It's fully working in local.
In production, the home route ("/") works, but all other routes throw an error 500.
If any specific route is put in the "/" route, it works.
The Slim site is hosted in a subdomain. A Wordpress site is hosted on the main domain.
It is hosted on a shared hosting by 1and1.
The exact error is:
Internal Server Error : The server encountered an internal error or
misconfiguration. Additionally, a 500 Internal Server Error error was
encountered while trying to use an ErrorDocument to handle the
request.
Several htaccess files were tried unsuccessfully.
Thank for your ideas to manage the issue!
You could try this one, it was working for an old project
<IfModule mod_rewrite.c>
# Activate this if you need to follow symlinks
#Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controller
RewriteRule ^index.php - [L] RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [QSA,L]
</IfModule>
can you please try this .htaccess file instead?
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
I have a CakePHP app that has some html static files in webroot.
HTML files are in some directories like webroot/dir1/dir2/page.html.
When I enter url: site.com/dir1 I get redirected to site.com/webroot/dir1/ but when I enter site.com/dir1/ I get redirected to the first page site.com
And If I enter url for the html file: site.com/dir1/dir2/page.html I get redirected to the first page site.com. It supposed to show the html file. How can I make it show html file and not redirect to first page?
In my public_html the htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
In the webroot the htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
It's definitely not connected to CakePHP. Just ignore your directory / ies that should not be processed by CakePHP's routing system, see this related SO post.
Insert .htaccess into your directory/ies that should be ignored:
RewriteEngine Off
your questions isn't about php,
it's about the apache Webserver or more about -> Apache Module mod_rewrite
Rewrite Engine is only called one time, so you have to put all changes in one File.
kind regards
set
I am trying to setup a custom 404 page for my website using: ErrorDocument 404 /404.html but when I add this, going to domain.com/dslkjflsdkjflskdjf doesn't redirect to the 404 page. Instead, it redirects to my homepage where mostly everything on the page is broken.
I'm wondering if this mod_rewrite.c module is the cause of this, I've tried modifying it (taking L out, adding the redirect inside the module, etc) but no luck.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>
I'm not sure about this but I think your server won't recognize a 404 error because every request is redirected to your index.php. You have to determine in the index.php if there is a 404 error and send the header with the header() function.
I took over a hosting account for a friend to host a second domain on his server. All is good, except for the .htaccess file that was generated by whoever designed his first site.
The main site is: ra-pictures.com, hosted in the root folder /
The site I'm working on is posthumanmovie.com, which is hosted in the folder /posthuman
Here's the current .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
# route non-existant requests to single script
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule ^.*$ index.php [QSA,NS]
</IfModule>
When I try to go to posthumanmovie.com - I get a 404 not found error.
When I delete the .htaccess file, it works, but his other site ra-pictures.com has 404 errors on any page that isn't the index page. Any ideas on how I can change the .htaccess file to allow access to all pages from both sites?
Add a condition to check against the hostname:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ra-pictures\.com$ [NC]
# route non-existant requests to single script
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule ^.*$ index.php [QSA,NS]
</IfModule>