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 )/(.*)$
Related
How can I rewrite the URL so instead of looking like this:
website.com/index.php/acars
it looks like this:
website.com/index.php?p=acars
and maybe like this:
website.com/acars
here is an example i use in a symfony2 project (i think it's the default symfony htaccess):
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
so every request like website.com/acars will be handled like website.com/index.php/acars
My current .htaccess for working with CakePHP 3 is:
./
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
./webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
My host provider recommends to set up the following .htaccess for automatic https redirects:
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://ihredomain.de/$1 [R=301,L]
How am I supposed to combine all these into one working htaccess without breaking Cake's routing?
I am somewhat afraid of the trial-and-error way, because it is a production system.
In the root folder i changed the .htaccess file to
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
That worked for me while all other solutions didn't.
You can use this in your /.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://ihredomain.de/$1 [R=301,L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
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>
I plan to have this as a URL:
https://SubDomain.domain.com/<locale>/Controller/action/param1/param2/?query=param3
in Lithium Framework (li3.me)
What is the purpose of the htaccess files in Lithium?
It should redirect me through .htaccess as:
https://domain.com/<locale>/Conttroller/action/param1/param2/?query=param3&subdomain=SubDomain
In Lithium framework there are 3 .htaccess files:
1. /.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
2. /app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
3. /app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Uncomment the line below, to enable HTTP authentication running PHP as a CGI.
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !favicon.ico$
RewriteRule ^ index.php [QSA,L]
</IfModule>
I tried to edit the root /.htaccess file to get the subdomain name as a parameter without any success.
Pass subdomain as parameter
Dynamic subdomain rewrite htaccess
.htaccess Wildcard Subdomains
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !mydomain\.com$ [NC]
RewriteRule ^(.*)$ app/webroot/$1?subdomain=%1 [L]
Do I have to rewrite rules in all 3 .htaccess files? If so, what are the changes needed?
Thanks!
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>