mod-rewrite subdomain to path in primary domain - .htaccess

I have content from a different server on a subdomain that I would like to use as a subdirectory. Everything from sub.domain.com should be accessible to domain.com/sub I would like sub folders to work as well ex: sub.domain.com/about should be domain.com/sub/about
Here's my current .htaccess contents
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(sorry).* - [NC,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Any help appreciated. Thanks!

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^ http://domain.com/sub%{REQUEST_URI} [R=301,L,NE]

Related

htaccess file to hide subfolder

I'm struggling with the .htaccess file. I've wordpress installed in a subdirectory 'wordpress'. In the root folder if have the htaccess with the following content:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule !^wordpress/ /wordpress%{REQUEST_URI} [L,R=301]
</IfModule>
Redirection is working, but how can I hide the subfolder 'wordpress'?
THX in advance
EDIT: Tried following content now but still not working:
root htaccess:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
</IfModule>
wordpress htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
EDIT2: my whole root htaccess looks like this now:
Allow from all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
If i type in www.example.com I am redirected to example/wordpress/home, example/wordpress/contact and so on...
I would like to hide the wordpress directory like example/home, example/contact and so on
Redirection is working, but how can I hide the subfolder 'wordpress'?
You shouldn't be "redirecting". You should be internally rewriting the request instead. Remove the R flag.
For example:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
The slash prefix on the susbtitution string is also not required.
This assumes you have the standard WP .htaccess file in the /wordpress subdirectory.
UPDATE: Also confirm you have removed the /wordpress subdirectory from the "Website Address" and "Site Address" in WordPress General settings.

Page redirection with .htaccess

I need to make a target, when the user access, https://www.dominio.com.br/portal/anything be directed to https://www.domain.com.br/blog
Is it possible to do this with .htaccess?
Here is the code I have:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule .* / [R=200,L]
RewriteRule ^portal/([a-z0-9\-]+)/$ ^blog/ [QSA]
</ifModule>
Note: Inside the portal folder, I already have an index.php pointing to blog. This .htaccess would go inside this folder.
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^portal/(.*) blog/$1 [L,QSA]
</ifModule>

Rewrite Role does not apply

I have php website and I have created .htaccess file. I have two rules. One for force www and other for permalink.
I want to change following Url
http://www.yatha.tv/play.php?vid=1437&id=1
to
http://www.yatha.tv/1437/1.html
But this rule does not change
RewriteRule ^([^/]*)/([^/]*)\.html$ /play.php?vid=$1&id=$2 [L]
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yatha\.tv$
RewriteRule ^(.*)$ http://www.yatha.tv/$1 [R=301,L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /play.php?vid=$1&id=$2 [L]
</IfModule>

cake .htaccess rewrite almost working

I'm having a problem with rewrite rules in my cake 2.2.0 app.
Mod_rewrite seems to be working as going here:
myapp.com/listings works
But links generated by cake construct this type of URL, which also work but are not being rewritten:
myapp.com/app/webroot/index.php/listings
I've tried a lot of posted options but nothing seems to work?
My apache config is set up as follows:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
All .htaccess files are standard from the cake install?
Webroot .htacess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
App .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Should I be looking at anything else?
This is something you should be able to fix in cakephp when you generate your links. The htaccess files that you have won't change the links in your page content.
If for whatever reason, you can't do this in cakephp, then you can add this to your Webroot htaccess, right below the RewriteEngine On line:
RewriteCond %{THE_REQUEST} \ /app/webroot/index.php/([^\ ]+)
RewriteRule ^ /%1 [L,R=301]
and that will redirect the browser to the shorter URL.
In case any one else looks at this, my problem was that this line in /app/Config/core.php was uncommented:
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
Commenting it out removed the abs URL /app/webroot/index.php/ from my URLs.
Happy coding.

Redirect query string to non-query string?

I am looking for an .htaccess rule, which redirects:
http://abcde.com/?q=abc
Where abc can be any string to:
http://abcde.com/
Add this to your .htaccess in your web root / directory
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^$ http://%{HTTP_HOST}/ [R=301,L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^q=.+ [NC]
RewriteRule ^$ /? [R=301,L]

Resources