Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove /public in URL not working if using localhost #2930

Closed
jlamim opened this issue May 4, 2020 · 6 comments
Closed

Remove /public in URL not working if using localhost #2930

jlamim opened this issue May 4, 2020 · 6 comments

Comments

@jlamim
Copy link
Contributor

jlamim commented May 4, 2020

During the creation of examples for my book on CI4 and tutorials to help the Brazilian community, I came across the need to configure the URL so that /public is not displayed without changing the default framewoprk structure.

I created a .htaccess file at the root of the application containing the following code:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

When I use a virtual host (eg http://public-htaccess.test) this code in .htaccess works normally, but if I get the same structure of the application using localhost (http://localhost/public-htaccess ) the code does not work correctly, says that the controller was not found, as he understands that the controller is public-htaccess.

Could someone tell me if it is possible to do this redirection for the use case with localhost and how would it be the correct way within the framework standards?

The documentation in this regard is not clear, so if you can give me feedback on this issue, I can also supplement the documentation with this information.

OS: Win10
Apache: 2.4.41
PHP: 7.4.5
CodeIgniter: 4.0.3

P.S.: @lonnieezell and @samsonasik can you help me?

@samsonasik
Copy link
Member

probably add .htaccess to root project with the following content:

RewriteEngine On
RewriteRule (.*) ./public/$1

@jlamim
Copy link
Contributor Author

jlamim commented May 5, 2020

Thanks for the feedback @samsonasik!

What I really need is to remove /public from the URL, leaving it clean, and not redirect to /public explicitly. For example:

Current: http://localhost/public-htaccess/public
Required: http://localhost/public-htaccess

But I need to do it in a way that does not require any changes to the framework structure or the configuration of paths in the settings.

When I apply the code presented in this issue to a virtual host, it works perfectly, even if the root directory configured on vhost is not /public, but the application root.

But if I apply the same code using localhost/public-htaccess, it doesn't work as expected, it redirects to localhost/public-htaccess/public.

I know that via htaccess there is no way to change the root directory. In this case of localhost, the only way would be a redirect, with /public explicit in the URL?

@paulbalandan
Copy link
Member

From the way your rewrite rules were written, I believe you need to set your httpd.conf to change the ServerName to localhost/public-htaccess. Since you are rewriting your URIs, /public-htaccess is treated as a URI rather than a part of the base URL.

@samsonasik
Copy link
Member

@jlamim could you verify if it related with #2965 and fixed by @Instrye at #2978 ?

The .htaccess example by at @willnode at https://github.com/willnode/crm-toolkit/blob/master/api/.htaccess

@MGatner
Copy link
Member

MGatner commented Aug 25, 2020

@jlamim Could you test with the latest code? Also check the links from @samsonasik above.

@paulbalandan
Copy link
Member

This issue is too stale and no feedback have been received so far. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants