i have two htaccess files, one for the root folder and another for the public folder. my problem is i'm getting an error because request for the favicon.ico is been processed. how do i stop the processing of the favicon?
below is my .htaccess files
:root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond ^([^/]+)/?$ !^favicon\.ico
# Stop processing if already in the /public directory
RewriteRule ^public/ - [L]
# Static resources if they exist
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule (.+) public/$1 [L]
# Route all other requests
RewriteRule (.*) public/index.php?request=$1 [L,QSA]
</IfModule>
:public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond ^([^/]+)/?$ !^favicon\.ico
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{REQUEST_URI} !^/javascripts/
RewriteCond %{REQUEST_URI} !^/stylesheets/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [NC,L]
</IfModule>
the public folder is in the root folder
Related
I have written .htaccess files to prevent frontend/web from appearing in url but when I saet links through Url::to it appears in url.
This is my .htaccess in root directory:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
# deal with admin first
RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^.*$ backend/web/index.php [L]
RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
RewriteRule ^(.*)$ frontend/web/$1 [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
</IfModule>
This is .htaccess file in frontend/web directory:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Please help me I have no idea what to do.
Use the following configuration in Apache's httpd.conf file or within a virtual host configuration. Note that you should replace path/to/frontend/web with the actual path for frontend/web.
# Set document root to be "frontend/web"
DocumentRoot "path/to/frontend/web"
<Directory "path/to/frontend/web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...
</Directory>
Yii2 Docs
Add below lines in to your .htaccess file and replace /to/base/path/ with your project directory path
RewriteCond %{REQUEST_URI} ^/to/base/path/
RewriteRule ^(.*)$ frontend/web/$1 [L]
You have a lot of questions about basic stuff. what about this
And you can see in them a lot of stuff for ccs and not only
Normally the index.php in laravel framework is in the /public_html/public/ folder.
In my case it is in /public_html folder
This is the code inside my .htaccess file
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
What changment should I make to exclude index.php from urls ?
The code structure is as follows :
/public_html/sitemap.xml
/public_html/sitemap.htm
/public_html/server.php
/public_html/robots.txt
/public_html/readme.md
/public_html/index.php
/public_html/.htaccess
/public_html/public
/public_html/database
/public_html/config
/public_html/cgi-bin
/public_html/bootstrap
/public_html/app
and inside /public_html/public
/public_html/public/web.config
/public_html/public/robots.txt
/public_html/public/favicon.ico
/public_html/public/upload
/public_html/public/js
/public_html/public/img
/public_html/public/css
I highly discourage moving index.php out from the public folder.
I was able to achieve what you are trying to do by following this tutorial.
There, you move your code base out from public_html folder to /appications/your-app folder and move content of public folder into public_html/your-app.
The tutorial is self-explanatory.
I use this Laravel project's structure too (index.php in the project's folder). In my case I did next:
rename server.php in the root folder to index.php
Make .htaccess in the root folder:
Insert this code inside the IfModule mod_rewrite.c
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.css|\.ttf|\.woff|\.woff2|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|fonts)/(.*)$ public/$1/$2 [L,NC]
After spending hours I write below code for me and its 100% working.
Use this code just after
RewriteEngine On
Redirect index.php to non index.php
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^index.php/(.*)$ /$1 [R=301,L]
I have a .htaccess file that should redirect all requests to index.php?url=$1, Except if the request points to images or specific files. If these are located somewhere undetr the public/ folder they should be served. If the requested file is an image somewhere out of the public/ folder then it is redirected to a default image, and if the requested file is a HTML, JS, CSS, SWF file and is out of the public/ folder a simle 404-not found should be sent back.
Everything works good except that when I request images from /public or let's say public/images they are redirected to the default image as well. I've tried everything, even the %{ENV:REDIRECT_STATUS} but still the same. Any Ideas how could I make the loop stop If the file has been served in the line 11.?
Here is the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
SetEnv HTTP_MOD_REWRITE on
RewriteBase /wsproject/
Options All -Indexes
DirectoryIndex index.php
RewriteCond %{REQUEST_URI} ^public/.*\.(html|css|js|swf|jpe?g|png|gif|bmp|ico)$ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} \.(jpe?g|png|gif|bmp|ico)$ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ public/errors/img-not-found.png [L]
RewriteCond %{REQUEST_URI} \.(html|css|js|swf)$ [NC]
RewriteRule ^ - [R=404,L]
RewriteCond %{REQUEST_URI} !^public/.*$ [NC]
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
I use the code from a former answer, you can see here: Apache Rewrite module, complex rules
Use THE_REQUEST variable instead of REQUEST_URI as your last rule is rewriting everything to /index.php and changing value of REQUEST_URI.
<IfModule mod_rewrite.c>
RewriteEngine on
SetEnv HTTP_MOD_REWRITE on
RewriteBase /wsproject/
Options All -Indexes
DirectoryIndex index.php
RewriteCond %{THE_REQUEST} /public/.+?\.(html|css|js|swf|jpe?g|png|gif|bmp|ico)\s [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{THE_REQUEST} \.(jpe?g|png|gif|bmp|ico)\s [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ public/errors/img-not-found.png [L]
RewriteCond %{THE_REQUEST} \.(html|css|js|swf)\s [NC]
RewriteRule ^ - [R=404,L]
RewriteCond %{THE_REQUEST} !/public/ [NC]
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
I have seen many sample/tutorial regarding my case but when i use their working code, it's not doing anything to my URL.
I want to make this link example/lmp/property/jumeirah_parklarge_legacy_4brms/V0004221/ to example/lmp/property/jumeirah-parklarge-legacy-4brms/V0004221/
I also test the .htaccess code in http://htaccess.madewithlove.be/ and it gives me the right output URL but when test on my local server it doesn't redirect me to output URL.
Here's my code,
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /lmp
RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3-$4-$5-$6-$7 [L,NC,E=underscores:Yes]
RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3-$4-$5-$6 [L,NC,E=underscores:Yes]
RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3-$4-$5 [L,NC,E=underscores:Yes]
RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3-$4 [L,NC,E=underscores:Yes]
RewriteRule ^lmp/property([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3 [L,NC,E=underscores:Yes]
RewriteRule ^lmp/property([^_]*)_(.*)$ lmp/property$1-$2 [L,NC,E=underscores:Yes]
RewriteCond %{ENV:REDIRECT_underscores} ^Yes$
RewriteRule ^([^_]+)$ lmp/$1 [R,L]
RewriteCond %{REQUEST_URI} ^../system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^../application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/?([^\ \?]*) [NC]
RewriteRule ^ %1/%2 [R=301,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /home
</IfModule>
You can use:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /lmp/
# recursive rule to replace _ by - from REQUEST_URI
RewriteRule ^(property)/([^_]*)_+([^_]*_.*)$ $1/$2-$3 [L,NC]
RewriteRule ^(property)/([^_]*)_([^_]*)$ $1/$2-$3 [L,R=302,NC,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/?([^\ \?]*) [NC]
RewriteRule ^ %1/%2 [R=301,L]
RewriteCond %{REQUEST_URI} ^../system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^../application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /home
</IfModule>
I'm facing a problem with a cakephp application.
On my server, I have a folder called DIGIPRESSKIT (this folder is used by the domain www.digipresskit-online.com), I placed all the cake's folders into it and when I load the page, there is no CSS, like cake can't access my webroot.
Is there any chance u check my .htaccess ?
I read lots of forums about that, and here is what they tell me to do :
Code: "root/.htaccess" (/DIGIPRESSKIT)
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteRule (.*) /app/webroot/$1 [L]
Code: "root/app/.htaccess" (/DIGIPRESSKIT/app)
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/$1 [L]
Code: "root/app/webroot/.htaccess"
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
Assuming you can have many domains on this host, you can try this solution:
.htaccess on servers root (/)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} digipresskit-online.com
RewriteCond %{REQUEST_URI} !^/DIGIPRESSKIT
RewriteRule ^(.*)$ one/$1 [L]
RewriteRule ^$ / [L]
RewriteRule (.*) /$1 [L]
</IfModule>
.htaccess on subfolder (/DIGIPRESSKIT)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
DIGIPRESSKIT/app and DIGIPRESSKIT/app/webroot/ no change