Htaccess ( or + Cakephp) - apache

I would like to know how can I configure a subdomain to a website.
Example
www.domain.com
subdomain.domain.com
How can I configure the htaccess to access the folder subdomain and use it
public_html
app
lib
plugins
vendors...
subdomain
app
lib...
this is my htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
thanks

in public_html/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !subdomain/
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_FILENAME} !subdomain/
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Related

.htaccess rewrite rule not working

I've been looking few different tutorials about it like
https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
and I thought it would be easy to do my own rewrite rule but I don't know why it's not working.
this is what I have in my htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp2/
RewriteRule ^lol portafolio [NC,L] # Change feed URL
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp2/index.php [L]
</IfModule>
# END WordPress
and when I write wwww.domain.com/wp2/lol it's not redirecting me to wwww.domain.com/wp2/portafolio which this code:
RewriteRule ^lol portafolio [NC,L] # Change feed URL
should do.. I guess it's not correct. Why it's not doing the rewriting correctly? I need to rewrite a bunch of URLS.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Try this code. it will help you
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Mod_rewrite working on http but not https

I have a mod_rewrite that works fine on http, but not on https.
Some answers on stack overflow to similar questions suggest adding RewriteBase /, but I already have that.
I'm hosted on godaddy on a shared server. I have contacted godaddy 3 times and they say they can't do anything.
Here is an example of the rewrite:
URL Without Rewrite:
https://www.funded.today/stats/?p=bloodstained-ritual-of-the-night
Mod_Rewrite URL:
https://www.funded.today/stats/iga/bloodstained-ritual-of-the-night
My htaccess file is the following:
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www\.)?funded\.today$ [NC]
RewriteRule ^$ https://www.funded.today/%{REQUEST_URI} [R,L]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^stats/(.*)/(.*)$ /stats/?p=$2 [P,QSA]
# BEGIN s2Member GZIP exclusions
<IfModule rewrite_module>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (^|\?|&)s2member_file_download\=.+ [OR]
RewriteCond %{QUERY_STRING} (^|\?|&)no-gzip\=1
RewriteRule .* - [E=no-gzip:1]
</IfModule>
# END s2Member GZIP exclusions
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.*)/(.*)$ - [L,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help or ideas on this is greatly appreciated!

.htaccess addon domain issue gives 500 error

This is my .htaccess located at public_html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I have a (legacy) CakePHP app running in public_html/app for maindomain.com
I added an addon domain otherdomain.com under public_html/otherdomain.
However, when trying to load the index page it returns a 500 server error.
Removing the public_html/.htaccess permits browsing otherdomain.com correctly, but the CakePHP app (maindomain.com) then has routing issues.
This is the CakePHP .htaccess under public_html/app:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
it appears that your main htaccess is redirecting traffic to your app/webroot/ which is causing problems for otherdomain.com.
Maybe you can check the hostname that is entered and redirect based on that.
Something like this.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^maindomain\.com [NC]
RewriteRule ^(.*)$ app/webroot/$1 [L]
RewriteCond %{HTTP_HOST} ^otherdomain\.com [NC]
RewriteRule (.*) http://otherdomain.com/$1 [L]
</IfModule>

Htaccess Redirect Wildcard

We have recently transferred our site to a new CMS and I am stuck on redirecting one directory.
Our old URL structure was this:
/directory/sub-directory/this-is-the-post/81281/
I want to redirect it to:
/this-is-the-post-81281
Current .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On
RewriteRule ^[^/]+/[^/]+/([^/]+)/([0-9]+)/?$ /$1-$2 [L,R]
#Redirected wildcard /new to forward slash.
RedirectMatch 301 /new/(.*) /$1
Put this code in your DOCUMENT_ROOT/.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^[^/]+/[^/]+/([^/]+)/([0-9]+)/?$ /$1-$2 [L,R]
RewriteRule ^new/(.*)$ /$1 [L,R]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
What I did in our .htaccess redirects
Redirect permanent /directory/sub-directory/this-is-the-post/81281 http://www.youdomain.com/this-is-the-post-81281

htaccess 301 redirect to different domain

Trust me, I've searched all over for a solution to my problem, so I don't believe this is a duplicate question.
I need to do the following:
301 Redirect blog.example.com to blog.newexample.com.
What I have is close to working. When I go to the homepage of blog.example.com it will redirect perfectly to blog.newexample.com. However, if I go to blog.example.com/directory/page it does not direct me to blog.newexample.com/directory/page.
Here is what my .htaccess looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !newexample.com$ [NC]
RewriteRule ^(.*)$ http://blog.newexample.com/$1 [L,R=301]
</IfModule>
# END WordPress
I'm not sure to understand what your problem is, but this works just fine :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newexample.com$ [NC]
RewriteRule ^(.*)$ http://blog.newexample.com/$1 [L,R=301]
</IfModule>
The URL http://website.com/hello/world/ redirects me to
http://blog.newexample.com/hello/world/.