Here is the file structure of my site
/app/
/controllers/
/views/
/lib/
/public/
.htaccess
I want to check if the requested URL is a file inside public dir
I tried this inside the .htaccess
RewriteEngine On
RewriteBase /app/
RewriteCond public/%{REQUEST_FILENAME} -f
RewriteRule (.*) public/$1
But this is not working. Any solutions?
You can try your check like this.
RewriteEngine On
RewriteBase /app/
RewriteCond %{DOCUMENT_ROOT}/app/public/$1 -f
RewriteRule (.*) public/$1 [L]
Related
I've built a php website working all fine with all the redirects except for http:// versions.
So I'm trying to edit my main .htaccess file to prevent http:// showing the error "NOT SECURE", and forward the user to https://
I've used a framework called TraversyMVC while building my website and it has the setup below in the public_html directory .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
And this is my .htaccess file in the /public directory
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
This is what I've tried in my public_html directory .htaccess file but it didn't work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} public/ [L]
RewriteRule ^(.*)$ https://www.mywebsite.com/public/$1 [L]
</IfModule>
Looking for the correct solution.
Thanks
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} public/ [L]
RewriteRule ^(.*)$ https://www.mywebsite.com/public/$1 [L]
You are redirecting the request before the internal rewrite to the /public subdirectory (so the second condition that checks for public/ will never match) and /public should not be in the visible URL you are redirecting to. You should also be explicit that this is an external redirect, not an internal rewrite. (As written this rule would result in an implicit 302 - temporary - redirect.)
This needs to go before the existing rules in the root .htaccess file. Try the following instead:
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
Test first with a 302 (temporary) redirect to avoid potential caching issues.
You do not need the <IfModule> wrapper.
I removed index.php using this .htaccess file:
RewriteEngine on
RewriteBase /job
RewriteCond $1 !^(index\.php|img|table-images|robots\.txt|css|fonts|js|uploads)
RewriteRule ^(.*)$ index.php/$1 [L]
Now Cannot debug with PhpEd. PhpEd need to acces dbg-wizard.php file in the root folder but it's not accessible anymore!
Change your code to this:
RewriteEngine on
RewriteBase /job/
RewriteCond $1 !^(index\.php|img|table-images|robots\.txt|css|fonts|js|uploads|dbg-wizard\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
Have added dbg-wizard.php to the list of things to skip.
I am using the following .htacces file in my domain root.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|admin|cache)
RewriteRule ^(.*)$ index.php [L]
One problem, is when I try to open the file located at cache/themes/theme1/global.css
But for some reasons it doesn't exclude the folder cache from the RewriteRule
Anyone know a solution for this?
I didn't test this but should work;
RewriteEngine on
RewriteRule ^(cache.*)$ $1 [L]
RewriteCond $1 !^(index\.php|images|robots\.txt|admin|cache)
RewriteRule ^(.*)$ index.php [L]
I'm trying to set a subfolder of my website as root:
RewriteCond %{REQUEST_URI} !^/home/.*$
RewriteRule ^(.*)$ /home/$1 [QSA,L]
This works fine when I go to http://www.mydomain.com/ it shows the content of http://www.mydomain.com/home but I get a file not found error when I try to go to, for instance, http://www.mydomain.com/anothersub.
Suggestions?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond $1 !^test/
RewriteRule ^(.*)/?$ /test/$1 [L]
</IfModule>
I have the following directory tree in public_html folder:
/app
/test
/cake
...
/app if the Application folder for my site and /test is a subdomain.
The problem is that I've changed the .htaccess, my site is working but the subdomain is returning a 500 error.
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Thanks.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain.com$
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain.com$
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Add the RewriteCond below to prevent an infinite internal redirect, which could result in a 500 error
#skip processing existing files e.g css. png etc
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^$ app/webroot/ [L]
#if not already /app/webroot to prevent infinite internal redirect
RewriteCond %{REQUEST_URI} !^/app/webroot/ [NC]
RewriteRule (.*) app/webroot/$1 [L]
500 error usually means something is wrong with the code, like a missing ; in your model, view or controller. Try double-checking that?