Codeigniter 3 subdomain not working for other pages - .htaccess

I have created sub-domain like this in Codeigniter 3
www.test.example.com
I have used this .htaccess and it's working only home page.
www.test.exapmle.com for other pages like www.test.exapmle.com/page1 or www.test.exapmle.com/page2
.htaccess I used:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public_html/index.php/$1 [L,QSA]
I am getting this error:
the server encountered an internal error or misconfiguration and was
unable to complete your request.

In .htaccess file just insert the following code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Related

rewrite rule on htaccess not working

Hi for some reason the htaccess file is not working properly
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mallyear.com$
RewriteCond %{REQUEST_URI} !^/prod/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /prod/$1
RewriteCond %{HTTP_HOST} ^(www.)?mallyear.com$
RewriteRule ^(/)?$ prod/ [L]
so all the files are in this directory prod/ but when i enter this url
https://www.mallyear.com/landing
it shows "The requested URL /prod/landing was not found on this server."
why is this happening? Please help

Codeigniter Error 500 in subdomain

So, I recently installed codeigniter in a subdomain and I'm getting 500 error when I try to access it. Script should run normal, I had it on several other domains and my guess it's htaccess on the main domain folder (public_html).
Here's the .htaccess from the "root" folder
#OLD
RewriteCond %{HTTP_HOST} ^domain.tv$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.tv$
RewriteCond %{HTTP_HOST} !^db\.domain\.com$ [NC]
RewriteRule ^/?$ http://domain.com/blog/topics/vidcast/ [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^blog/index.php/archives/category/podcast/feed$ http://feeds.feedburner.com/domainPodcast [R=301,L]
#RewriteCond %{HTTP_HOST} !^(www|ftp|webmail)\.milaraki\.com
#RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
#RewriteRule (.*) http://domain.com/blog/wp-content/uploads/%1/$1 [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
And here's the .htaccess in the subdomain (named: db.domain.com)
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Now, whenever I try to access "http://db.domain.com", it redirects me to "http://db.domain.com/blog/". If I try to access by subfolder
like "http://domain.com/db" it give's me an 500Error.
We also get these spam of lines in apache/error_log:
warn] (103)Software caused connection abort: mod_fcgid: ap_pass_brigade failed in handle_request function
Also, let me tell you it's in a VPS and the "root" .htaccess file it's not made by me, but from the client, all I have done, it's to add an extra line in his .htaccess file to "stop" the redirect but it's not working at all.
That's the line I added (already in the code i posted)
RewriteCond %{HTTP_HOST} !^db.domain.com$ [NC]
It still gives the error even if I remove it or leave it there.
Oh and, in the "root" folder, he installed WordPress.
Hope I was clear enough, feel free to ask me other questions.
So, I ended up removing the lines bellow from the .htaccess file inside the "root" folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
Restarted Apache (no idea why this is necessary) and the new settings fixed everything...

How to stop .htaccess ReWrite rules affecting Subdomains

I have this code in my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(online-shop)/?$ $1/home [L,NC]
RewriteRule ^(my)/?$ $1/home [L,NC]
RewriteRule ^(blog)/(post|tags)/([\w-]+)/?$ index.php?id=$1&type=$2&unique=$3 [L,QSA,NC]
RewriteRule ^(blog)/(archives)/([0-9]{4})/([0-9]{2})?$ index.php?id=$1&type=$2&year=$3&month=$4 [L,QSA,NC]
RewriteRule ^([\w/-]+)/?$ index.php?id=$1 [L,QSA]
So the following URLs are rewritten:
domain.com/home to domain.com/index.php?id=home
However if i look at a subdomain (cp.domain.com) i get the following error:
The requested URL /home/user/public_html/index.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
so the subdomains are looking in the ROOT directory for the domain however they should be looking in the directory set in the control panel
As soon as i remove this line of code:
RewriteRule ^([\w/-]+)/?$ index.php?id=$1 [L,QSA]
the subdomains start working fine
You can try to restrict last rule to only work for main domain:
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w/-]+)/?$ index.php?id=$1 [L,QSA]

htaccess file misconfigured

I am using codeigniter php framework. I am trying to access a folder under public_html, but I can't get to it. It shows 404 custom page by codeigniter. Does the following script in .htaccess has something to do with it?
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Thanks
It probably is, you can try adding either some conditions:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Or include your folder as part of the exclusion (example, your folder is "foobar"):
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|robots\.txt|foobar)
RewriteRule ^(.*)$ /index.php/$1 [L]

codeigniter htaccess rewrites the url to the BASEPATH../

i have a website that i made with codeigniter it works relativly fine on the local machine but when i uploaded it to the server it gives me a 500 error, and the error is gone when i remove the htaccess, and in the local machine the error appears in a different way some times i couldn't find what causing this but some urls get rewritten like this:
the original url => http://domain.com/controller/method
the rewritten url => http://domain.com/absolute/path/to/controller/method
here's my htaccess file:
RewriteEngine On
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
any help, thanx in advance.
try with my .htaccess code........
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Resources