Here is my .htaccess file content
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ main/ [L]
RewriteRule (.*) main/$1 [L]
</IfModule>
Here is my directory structure
www
|- ads
|- main
|- .htaccess
With this configuration all website ex.(http://www.sitename.com) incoming links are meant to go to index.html on sub directory main.
Now I want to make an exception ex.(http://www.sitename.com/ads), to redirect to the sub directory ads.
How can I do that?
Thanks
You have 2 solutions:
Add a rule for "ads" before others
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^ads$ ads/ [L]
RewriteRule ^$ main/ [L]
RewriteRule (.*) main/$1 [L]
</IfModule>
Or don't rewrite for existing directories
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ main/ [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) main/$1 [L]
</IfModule>
Related
I have the follow project structure:
public_html/
|- app/
|- webroot/
|- news -> symlink to ../../news/webroot/
|- .htaccess (see code 1)
|- .htaccess (see code 2)
|- news/
|- webroot/
.htaccess 1
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
.htaccess 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(img|css|js|fonts)/(.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
When I request /news (as a pretty URL managed by the framework), the request is redirected to /webroot/news/ by apache, instead of load the news. I can't find what is wrong, what is your suggestion?
So, if I click: news the page is redirected to /webroot/news/. If I click: news/ the page is redirected to /news/
(Using subdomain inside the domain of cPanel)
Turn directory trailing slash off in your root .htaccess since mod_dir adds a trailing slash after mod_dir. As a last rule add trailing slash back again internally:
.htaccess 1:
<IfModule mod_rewrite.c>
DirectorySlash Off
RewriteEngine on
RewriteBase /
RewriteRule (.*) webroot/$1 [L]
# add trailing slash for directories
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)/$ $1 [L,NE]
</IfModule>
public_html/app/.htaccess
Deleted file
public_html/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(img|css|js|fonts)/(.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Subdomain pointed to public_html/app/webroot/
SOLVED.
I have a website working on one server. I am changing hosting, so I created a website on another server for testing.
Everything seems to be working, except CSS. It is not loading at all. I have 777 for tmp folder and mod re_write enabled.
I can see all cached files except for CSS.
Please advise and help
This is my .htacess file in www
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This is my second htaccess inside app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
This is my third htaccess inside webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
and the url is 23.236.49.24
Add this line:
RewriteBase /
under
RewriteEngine On
in the 3 .htaccess files
Create .htaccess file in webroot folder.
And paste this code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
I have this path in my hosting server with domain http://www.example.com/ and it's running cakephp in the directory home. but now I want my another_project_name appear in browser with http://www.example.com/another_project_name/.
This is my structure :
/www
.htaccess
home/
.htaccess
webroot/
.htaccess
lib/
another_project_name/
This is my /www/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ home/webroot/ [L]
RewriteRule (.*) home/webroot/$1 [L]
</IfModule>
How to configure .htaccess file in /www/.htaccess to make my another_project_name work ?
Try this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (another_project_name/.*) $1 [L] # adjust the regex to what you want.
RewriteRule (another_project_name.*) $1 [L] # adjust the regex to what you want.
RewriteRule ^$ home/webroot/ [L]
RewriteRule (.*) home/webroot/$1 [L]
</IfModule>
.htaccess file should be like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/?(another_project_name)/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
For multiple directories
RewriteCond %{REQUEST_URI} ^/?(another_project_name1 | another_project_name2 | another_project_name3 )/(.*)$
I'm trying to install cakephp on a 1&1 account but running into problems.
I believe I need to add
RewriteBase /path/to/cake/app
to the htaccess file but I can't figure out what the path should be.
I have put the cakephp files in a folder called scissors on the most bottom level of folders I can browse to using filezilla. With that in mind I tried
RewriteBase /scissors/app
but that didn't work. What should it be?
EDIT:
I have managed to get the site to work (sort of) but unfortunately the css doesn't seem to get loaded.
The three htaccesses which I have which are working but not pulling the css are:
in /scissors
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /app
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
in scissors/app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
in scissors/app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Does anyone have any idea why this isn't correctly loading the css?
thanks
Answer is for cake 2.0 and I'm assuming that you've unzipped downloaded archive inside your public_html, so the path to cake looks like
/home/your_login/public_html/scissors/files_and_folders_unzipped_here
Or just
/public_html/scissors/files_and_folders_unzipped_here
as
/home/your_login
may not be visible.
Inside "scissors" folder (where app, lib, plugins, vendors etc folders are) place .htaccess with
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Inside "app" folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
And inside "webroot" folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
There is one more way to install cake (allows to have multiple sites on one "core config") but unzipping everything inside public folder is the easiest one.
I have a CakePHP installation in a sub folder in my server, I want to install another application inside that subfolder:
root/public_html/subfolder/cake/
root/public_html/subfolder/app/
etc. now I need a custom application installed there:
root/public_html/subfolder/my_custom_application/
I have something like this in my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
How can I configure it to exclude the "my_custom_application" folder from that rules?
I tried this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule ((?!my_custom_application).*) app/webroot/$1 [L]
</IfModule>
But I get this:
Error: The requested address '/y_custom_application' was not found on this server.
Thanks in advance.
Mauricio.
How to Exclude a Directory from CakePHP Routing:
I ran into the same problem as you. I struggled, but finally found something that worked.
(I'm replying because the answer above didn't work for me, but this did).
My directory structure:
root/public_html/app/
root/public_html/lib/
root/public_html/plugins/
root/public_html/vendors/
root/public_html/directory_to_exclude/
What I added to CakePHP's default routing:
RewriteCond %{REQUEST_URI} !^/directory_to_exclude/(.*)
Effectively, I needed to allow people to access the subfolder separately (since that has a separate application). Also, in my case, I'm serving a CakePHP application by default from the root directory.
So here's what my CakePHP 2.x htaccess looks like:
Updated .Htaccess (this works for me)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/directory_to_exclude/(.*)
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
In your case, I understand you need this to work in a subfolder; here's my adjusted htaccess I didn't have a chance to test this, but I believe this (or something close) will work:
The Final Product (for a subfolder)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subfolder/directory_to_exclude/(.*)
RewriteRule ^$ subfolder/app/webroot/ [L]
RewriteRule (.*) subfolder/app/webroot/$1 [L]
</IfModule>
Put this before the RewriteRule lines:
RewriteCond %{REQUEST_URI} !^/my_custom_application
You have to replace dir_to_exclude by your dir name.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude)(?:$|/)
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude)(?:$|/)
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
If you want to have more than one excluded directory you have to add them separated by |additional_dir_to_exclude
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude|additional_dir_to_exclude)(?:$|/)
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude|additional_dir_to_exclude)(?:$|/)
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>