.htaccess file is not working - php

RewriteEngine on
RewriteCond $1 !^(index\.php|img|css|gallary|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Above is the code exist in .htaccess.
I want the rules such as every request made to main domain or subdomain must hit the index,php file in the domain root.
exm.
api.xyz.com, api.xyz.com/register, api.xyz.com/login
all this request must have to go to index.php
I am facing this error on ipage web host.
Please suggest if anything wrong the host too.

Try this rule:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php/$1 [L]

Related

Redirecting from document root to folder with htaccess

My directory structure is like this and my document root is /
/
.htaccess
/public
This is all on my local xampp server.
The server is set up to listen for mydomain.local and in my hosts file I have pointed mydomian.local to localhost.
I am using the following .htaccess code and it works fine when using mydomain.local as the address.
The problem that I am having is that it does not work when I am using localhost/mydomain as the address
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php?path=$1 [NC,L,QSA]
How can I get it to work when using localhost/mydomain as the address?
The reason for this is because I am trying to register service worker but they only work over https or localhost.
Thanks in advance
I fixed it.
root folder .htaccess
RewriteEngine On
RewriteRule ^$ public/$1 [L]
RewriteRule ^(.*) public/$1 [L]
public folder .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [NC,L,QSA]
Thanks
You may also keep a single .htaccess file at root by changing a bit your rewrite rule to add an optional mydomain/ in match but not using it :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Add optional group
RewriteRule ^(mydomain/)?(.*)$ /public/index.php?path=$2 [NC,L,QSA]
# Same with a non capturing group
RewriteRule ^(?:mydomain/)?(.*)$ /public/index.php?path=$1 [NC,L,QSA]
By the way, you can use htaccess tester to check effects of rules rewriting on url

I have problems with my codeigniter webapp it works fine on my local host but not on live server

Can any one help me?
I code a web app in php with codeigniter
it works well on my localhost but when I upload it on live server it loads only home page. For other pages it gives a error
''No input file specificed''
When I do google about it.
There are many tricks like change .htaccess but no one works.
What should I do
Check this
It loads foodpark.tk
But does not load
Foodpark.tk/category/index
And all the other pages
this is my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
Options -Indexes
i also tried to put a question mark after index.php in .htaccess but it gives 404 error from hosting
Sorry for my poor english
Try this in your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
Try this.
In your .htaccess file Change
RewriteRule ^(.*)$ index.php/$1 [L]
To
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Try below code in .htaccess. This is from my working project. Hope you are using godaddy server.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

.htaccess file not working properly in the sever

I'm developing a web site using Codeigniter 3.X. my issue is that it works fine in localhost. now i uploaded the same to my server but it shows some error like "The page you requested was not found."
my htaccess file looks like this:
RewriteEngine On
RewriteBase /fold1/mainfold/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 ^(index\.php|robots\.txt|favicon.ico|images|smileys|js|assets|css)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /fold1/mainfold/index.php?/$1 [L]
what is issue with this code ? please help me...
Check the flowing:
Does the paths exist on your server?
Is mod_rewrite enabled on your Apache?
This code for hiding the index.php file .
And for Controller and method better to use route.php file.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I found the reason behind the issue. am using codeigniter3.X .Its file naming rules says that controller and model name should be starts with capital letter. i renamed my controller and model files. now the issue is resolved.
try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Codeigniter Installation Moved

I recently moved my codeigniter application from a subdomain to operate under my domain.
Basically I moved it from:
https://account.mywebsitehere.com
To:
https://mywebsitehere.com/account
Now when I try to access anything like /invoices it removes the /account from the url and results in a not found page. I have changed the base url in the config file but it is still resulting in this error.
Other than going through the entire application and changing every link to be /account/... How can I make the application work under the /account in the url?
My .htaccess file located at public_html/panda/.htaccess is as follows:
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]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mywebsitehere.com/panda/$1 [R,L]\
Try to change base_url to:
$config['base_url'] = 'https://mywebsitehere.com/account';
just put that code in .htaccess file and try it
RewriteEngine On
RewriteBase /account/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
first, upload an image to the root directory and see if you can access it within the browser.
if you cant access it , check your server's configuration and your .htaccess file.

How to use mod_rewrite to redirect requests of username but rest to a frontend index?

I am trying to redirect requests of username to a script but the all rest to a specific index called frontend.php using a .htaccess and a mod_rewrite.
Unfortunately, this failed and I keep struggling:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ frontend.php [QSA,L]
RewriteRule ^/user/([^/]+)$ profile/profile.php?u=$1 [QSA,L]
Thanks for your help!
You can use:
RewriteEngine On
RewriteRule ^user/([^/]+)$ profile/profile.php?u=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ frontend.php [L]
.htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.
Have you tried to swap the last 2 lines against each other?

Categories