.htaccess weird redirect PHP MVC - php

For anyone interested this was solved very simply by putting the root of my site to the public folder, Rookie error.
Hello ive just finished setting a website, and i am getting a weird redirect issue. When i first type in the URL https://project-wheels.co.uk when it gets to the site it redirects to https://project-wheels.co.uk/public. This still works fine as this is where the project index is.
My directory is as follows
Application [folder]
public [folder]
.htaccess
Inside this first .ht access is
RewriteEngine on
RewriteRule ^(.*) public/$1 [L]
Then inside the public folder i have another htaccess
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The index file in the public folder starts the mvc application etc.
I used the mini-master template and i have no experience at all with htaccess files other than these.
To give a little more information this website is actually hosted as a Addon domain and is routed to a folder in the public_html folder of the root, Im not sure if this makes any difference.
Thank you in advance
Ryan

try this on your first .htaccess
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

Related

Can't remove codeigniter's index.php in a subfolder of a wordpress site on root

I'm aware of a lot of solutions around there, and tried everything. The problem is, when I put a .htaccess in the codeigniter subfolder, it's not read. I thinks it's because of the AllowOverride directive, but I can't change that.
I tried to skip the main subfolder that is not part of wordpress, one I called "sandbox", in the root htaccess (that's part of wordpress), so it doesn't "inherit" any problem from that rewrite (for example, to not have 404 managed by wordpress in the codeigniter project).
The problem is, as I said, that the .htaccess in the /sandbox/ciproject/ folder is not read. So, I tried this in the main .htaccess, and it worked... for a little time.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?sandbox/
RewriteRule . /index.php [L]
RewriteBase /sandbox/ciproject/
RewriteCond $1 ^(application|system|private|logs)
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|img|fonts)
RewriteRule ^(.*)$ - [PT,L]
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
That allowed me to make it work for a while... but it's not working anymore. Something more I could try? I already changed the config of the codeigniter project so it doesn't use index.php, but nothing. I only get a server error 500 now, and if I delete the second half of the htaccess, I only get 404 as a response for getting rid of the index.php
I don't know if I'm losing some data, but just ask and I'll edit this, so you're not blind at this one.
Based on my understanding, your code-ignitor part doesn't work because, you have two clashing rewrite rules in your htaccess.
RewriteRule ^(.*)$ - [PT,L]
RewriteRule ^(.*)$ index.php/$1 [PT,L]
These are a clashing rule set. Remove one of the lines and then try. It should work.
Use only this code in htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sandbox/ciproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

htaccess subdomain with subfolders access

I am trying to rewrite the subdomain request to a subfolder in my server using .htaccess. I want mail.domain.com to look into mail folder located in the root. I am able to achieve this with the below code
RewriteEngine on
RewriteCond %{HTTP_HOST} mail.domain.com$
RewriteCond %{REQUEST_URI} !^/mail
RewriteRule ^(.*)$ /mail/$1 [L]
This WORKS correctly. When i browse to mail.domain.com i am getting the contents of domain.com/mail/index.php.
However this doesn't work with the subfolders inside the subdomain. ie when i browse to mail.domain.com/installer it DOESN'T give the contents from domain.com/mail/installer/index.php. Instead it shows 404 error. I also tried the code from htaccess subdomain pointing . Somehow I am unable to get the output. That method also gives the same problem. What am I doing wrong?
Note:
I do not want redirect conditions. Want to achieve via rewrite rules.
I am using openshift server. created domain.com & mail.domain.com aliases.
Root folder contains wordpress with no below .htaccess rules.
Edit
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
When I remove the above wordpress htaccess all works well. So it is causing 404 error in subdomain subfolders. Please help what i can do for both wordpress pretty urls and subdomain subfolders to work?
Note: I am really sorry. Wordpress added this via web interface and i failed to notice that.
Keep your root .htaccess like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} =mail.domain.com
RewriteRule ^((?!mail).*)$ mail/$1 [L,NC]
RewriteRule ^(index\.php$|mail) - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

My .htaccess file is not working

i have added my project on free hosting 000webhost and my all files are listed in public_html/ directory.
project is built in codeigniter.
i have added htaccess file at public_html/.htaccess which contains
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
but this does not working for me is there any issue in htaccess?
I use this (it works for me in both, locally and remotely):
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
You need to create a folder called "public" in the root rolder and sub-folders for css, js etc.
Sorry from all my htaccess is ok but i had an extra chracter in my base url which was causing problem.
Sorry again.

.htaccess Root Rewrite Without Folders

I've spent countless hours searching for similar issues and found the solutions to not work for me. I have an index.php with an 'id' GET variable to load pages dynamically as mydomain.com/[idVariableHere].
My .htaccess code works:
RewriteEngine On
RewriteBase /
RewriteRule ^(js|css|images)($|/) - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?id=$1 [L,QSA]
However, it's not preventing the /js/, /css/, and /images/ folders from being displayed. It's interfering with the last RewriteRule and I have no idea how to get around this.
My goal is to keep the mydomain.com/[idVariableHere] look with restriction on these important folders. Please help.
Have it this way:
ErrorDocument 404 default
ErrorDocument 403 default
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?id=$1 [L,QSA]
From what I understand, you want an .htaccess to prevent access to /js/, /css/, and /images/ folders. Assuming these are found in the root. Just create an .htaccess file in each folder with the following code:
deny from all
This was taken from:
deny direct access to a folder and file by htaccess

2nd Level .htaccess not working

I used to have two .htaccess files in my projet, We have the following directories.
MainProject/
.htaccess //first .htaccess
public/
.htaccess //second .htaccess
The projects used to work fine, but once I've uninstalled and installed apache, everything changed.
This is .htaccess 1 :
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
And, this is .htaccess 2 :
RewriteEngine On
RewriteCond %{REQUEST_URI} !/public/* [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
I activated the mod_rewrite module.
If I write in the address bar :
http://myproject.lan/
It takes me to the home page, meaning that .htaccess 1 is working just fine.
But when I write something like :
http://myproject.lan/login
It doesn't work, and it shows a "page not found" message.
What happens when project works, is that /login = $1 , so, it looks for public/login (in .htaccess 1)
Then, in public directory, the server executes the second .htaccess, where $1 matched to /index.php?url=/login, which is eventually sent to the front controller, waiting to be processed and converted to an existing route.
If there's something I need to enable on Apache, let me know because I forgot how I managed to make it work before in the first place.
Thank you
Your /public/.htaccess should be like this:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [L,QSA]
Problem is presence of RewriteCond %{REQUEST_URI} !/public/* [NC] condition in this .htaccess
I just found the solution to my problem, The problem is that in my
httpd-vhosts.conf
I forgot to add /public to the DocumentRoot.
Thank you

Categories