I have a website on Joomla 1.5 in my base dir - http://example.com - and another project written in Kohana 2.x - http://example.com/app.
The problem is that .htaccess in the subdirectory isn't working properly.
Question: How and which one .htaccess to configure? In subdirectory, my .htaccess file looks like this:
RewriteEngine On
RewriteBase /app/
RewriteRule ^(application|system) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
The project in subdir always tries to go to the controller named "app" when I type "http://example.com/app".
I have added the following:
RewriteRule ^(.*)$ index.php/$1 [PT,L]
RewriteRule ^$ index.php/$1 [PT,L]
And it is working perfectly!
The problem was with the hosting server. It did not handle the PT correctly and required to add above lines.
Everything worked fine:
https://example.com/app/auth
https://example.com/app/controller_name/param
However, the following did not work:
https://example.com/app
Seems like the index.php hasn't been added when nothing else were passed. Hence the line:
RewriteRule ^$ index.php/$1 [PT,L]
Related
I have a problem regarding my .htaccess file. It is placed in the root folder of my site together with the index.php (my front controller) and the folders regarding CSS, JavaScript, and images. The following is the URL-related content of my .htaccess file
# skip existent files
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule index.php - [QSA,L,C]
RewriteRule .* - [QSA,L]
# protect PHP files from the outside
RewriteCond %{REQUEST_URI} ^.*\.php$
RewriteRule ^.*\.php$ - [R=404,L]
RewriteCond %{REQUEST_URI} ^img/*$
RewriteRule ^img/*$ - [QSA,L]
# refer root to index.php
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ index.php [QSA,L]
# redirect 404 for non existent files
RewriteCond %{REQUEST_URI} ^(.*)\..*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\..*$ - [R=404,L]
# adjust the rest of the domains
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?site=$1 [QSA,L]
When I then open the website in the browser, it does not load the respective resources. If I click on "show image source", it immediately refers to the 404 page.
Do you have any idea which part I need to adjust to work around this problem? The root structure looks as follows
root
-.htaccess
-/css
-/js
-/img
-index.php
Thank you very much in advance! :)
EDIT 10/08/2021:
I figured out that the problem was stemming from other RewriteRules which I put into the last section right before RewriteRule ^(.*)$ index.php?site=$1 [QSA,L], e.g.:
RewriteRule ^study-programmes/(.*)$ index.php?site=study-programmes&faculty=$1 [L]
However, I have several pages where I need specifically named parameter (such as faculty in the example above). What exactly do I need to adjust in order to make it work?
The image matching rules are not written correctly. The . is missing from the rule.
RewriteCond %{REQUEST_URI} ^img/.*$
RewriteRule ^img/.*$ - [QSA,L]
I have a "mysite.com" and I want when it loads to load contents from the "mysite.com/new-site" folder.
My .htaccess now looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^/?$ "http\:\/\/mysite\.com\/" [R=301,L]
RewriteRule ^(/)?$ new-site/ [L]
And it loads the html but withoute any css, js or images. How can I tell the htaccess to load them from the new-site directory ?
You could use something like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:[^/]*/)*([^/.]+\.(?:jpe?g|gif|bmp|png|tiff|css|js|images))$ /new-site/$1 [R=301,L,NC]
EDIT:
Here's a bit more code with a little explanation so you can notice where everything is on your server.
RewriteEngine On
RewriteCond %{THE_REQUEST} "index.php"
RewriteRule ^index.php$ public/ [R=301,L]
RewriteRule . public/index.php [QSA,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:[^/]*/)*([^/.]+\.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /public/assets/$1 [R=301,L,NC]
So at first it says to search for index.php ( in your case it could be index.html or anything else where the site starts at first), after that it says to redirect to folder public/ on the server, since idex.php is located in /www/public or /public_html/public, in your case it could be /www/new-site/ so you'd do new-site/ in that part of the code, next add the same for . so new-site/index.php or whatever it is in your case. On the last part it says to search for files that end with jpg/jpeg, gif, bmp, png, tiff, css or js in /public/assets/, in your case it could be new-site/assets/ or just new-site/.
Hope this clarify's it a bit.
Use:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.exemple\.com$ [NC]
RewriteRule ^ http://exemple.com%{REQUEST_URI} [NE,R=301,L]
RewriteRule ^((?!new-site/).*)$ /new-site/$1 [L]
I have URL like :
localhost/admin/app/webroot
For this the css in default.ctp taken /app/webroot/css/style.css path.
so my css is not loading.
Should I have to change .htaccess file for this ?
There are 3 .htaccess file in project.
1) which is located in admin/.htaccess
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
2) which is located in admin/app/.htaccess
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
3) which is located in admin/app/webroot/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
please help to resolve my problem.
Thanks in advance.
The simplest way of dealing with this is to set your application up in "Production Mode" as described here
Essentially it means you point your document root to the /app/webroot directory of your Cake App, this makes everything really simple and means you can use the default .htaccess files to handle the rewriting.
If you are trying to put this into a subdirectory you might need to set the base for Rewrite to work on:
RewriteBase /admin
This also assumes you have mod_rewrite enabled on your server!
I found the answer :
If we can add
Configure::write('App.base', '/admin/');
in bootstrap.php file then it works for me.
Thanks for your help.
My primary website use Kohana framework. And I want create any directory (addon) with CI framework. I have success access the root of addon directory with addition .htaccess rule in Kohana/primary domain:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^site\.com [NC]
RewriteRule (.*) http://www.site.com/$1 [L,R=301]
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteRule ^(index\.php|sitemap\.xml|addon) - [PT,L]
RewriteRule .* index.php?/$0 [PT,L,QSA]
I success when type site.com/addon.
I have 3 url again in my addon site such us site.com/addon/about, site.com/addon/link, site.com/addon/contact. When I edit again the .htaccess in primary domain to access the another links of my directory, but its failed.
RewriteRule ^(addon|addon/about|addon/link|addon/contact) - [PT,L]
When I type in URL site.com/addon/about
I got
HTTP_Exception_404 [ 404 ]: The requested URL addon/about was not found on this server.
SYSPATH/classes/kohana/request/client/internal.php [ 87 ]
How to access full or all of my directory file (addon) links without get any trouble ? Because I also check my admin on addon/admin also crash, all function in framework CI will crashed. Solving this is appreciate.
.htaccess CI:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
You need to not rewrite if you are looking to use the addon directory. Something like
RewriteEngine On
RewriteBase /
#forbidden for these folders
RewriteRule ^(application|modules|system) - [F,L]
#do not rewrite requests to addon or test directories
RewriteCond %{REQUEST_URI} !^(/test|/addon)
RewriteRule ^(.*)$ index.php/$0 [PT,L]
http://htaccess.madewithlove.be/ can be helpful with .htaccess issues.
The is my real folder scheme:
ROOT
index.html
news.html
+articles
|-obama.html
|-oil.html
I want some htaccess rule so if people go to domain.com/obama.html the server will fetch the one in the articles folder without redirecting.
If some one goes to domain.com/index.html will still fetchs the one in the articles even if there is an index in the ROOT.
Thanks
Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond articles/%{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ articles/$1 [QSA]
RewriteRule .* articles/$1 [L,QSA]
Why don't you just use:
# RewriteRule /obama.html$ /articles/obama.html [L]
RewriteCond %{REQUEST_URI} !^/{index,news}.html$
RewriteRule (.*)$ /articles/$1 [L]
?