My Setup using cPanel:
domain.com(/public_html/)
mysub.domain.com(/public_html/2013/sitepath/)
Goal: for sub2.mysub.domain.com/save-path-info to redirect to mysub.domain.com/save-path-info without change the url from sub2.mysub.domain.com. In other words, I want anysub.mysub.domain.com to be virtually the exact same as mysub.domain.com.
Code:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.2013.cqueue\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.2013.cqueue\.com$ [NC]
RewriteRule (.*) /2013/sitepath/$1 [L]
The code above was originally in the root directory of mysub.domain.com but it wasn't working until I moved it to the root directory of domain.com. It successfully keeps the URL and path, however it is breaking the relative path of my templates.
Example: templates normally look for the path to be / but, with the rewrite above the templates think they need to look in /2013/sitepath/
EDIT
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^\.]+\.mysub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://mysub.domain.com/$1 [L]
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName domain.com
AuthUserFile /home/uadmin/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/uadmin/public_html/_vti_pvt/service.grp
Try this code :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^\.]+\.mysub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://mysub.domain.com/$1 [L]
Related
I know there are lots of similar (read: identical) questions, but I've tried everything - doesn't work.
This is my code:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [L,NE,R=301]
RewriteRule ^admin/(.*)$ backend/web/$1 [L]
RewriteRule ^developers/(.*)$ api/web/$1 [L]
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
Everything I get is only a redirect loop.
I'm using Heroku.
Thanks.
I have a few sites hosted on the same server,
but there is only one htaccess file that i guess governs all of them.
so how can i make index.php the default instead of index.html for only one of these sites?
thanks!
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName site1.com
AuthUserFile /home/myuser/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/myuser/public_html/_vti_pvt/service.grp
AddHandler server-parsed .shtml
AddHandler server-parsed .html
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site1\.com
RewriteRule ^(.*)$ http://www.site1.com/$1 [R=permanent,L]
RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteRule ^(index\.html)?$ /index.php [L,NC]`
For any particular site www.site.com have this rule in your .htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com$ [NC]
RewriteRule ^(index\.html)?$ /index.php [L,NC]
Suggested .htaccess:
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site1\.com
RewriteRule ^(.*)$ http://www.site1.com/$1 [R=permanent,L]
RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteRule ^(index\.html)?$ /index.php [L,NC]
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName site1.com
AuthUserFile /home/myuser/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/myuser/public_html/_vti_pvt/service.grp
AddHandler server-parsed .shtml
AddHandler server-parsed .html
Found a few similar questions but either I cant figure it out from the answers or they dont directly match my needs.
What I am trying to achieve is this:
I recently moved part of my site to a sub domain on a different server so what used to be in: http://mysite.com/clients is now on http://clients.mysite.com
using: RedirectMatch 301 https?://mysite.com/clients/^(.*)$ https://clients.mysite.com/$1 works fine for simply redirecting people hitting http://mysite.com/clients to the new sub domain however I would like to be able to preserve the string after /clients/
so if someone hits e.g. http://mysite.com/clients/could_be_a_number_of_things.php it redirects to http://clients.mysite.com/could_be_a_number_of_things.php
Can anyone advise?
full .htaccess as requested:
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
#AuthName mysite.com
#AuthUserFile /home/inhost/public_html/_vti_pvt/service.pwd
#AuthGroupFile /home/inhost/public_html/_vti_pvt/service.grp
# BEGIN WordPress
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS}s on(s)|
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$
RewriteRule ^clients/(.*)$ http%1://clients.mysite.com/$1 [L,NC,R=301]
</IfModule>
# END WordPress
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory on mysite.com server:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS}s on(s)|
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$
RewriteRule ^clients/(.*)$ http%1://clients.mysite.com/$1 [L,NC,R=301]
I have written a rewrite rule to get all pages looking like
dealer_listings.php?territory=arizona
to be accessible like this
wholesale-parts/arizona/
I would like the ugly url to redirect to the seo friendly one as well.
Options -MultiViews
RewriteEngine on
<FILES .htaccess>
order allow,deny
deny from all
</FILES>
RewriteRule ^([^/\.]+)/+([^/\.]+)/([^/\.]+)/?$ bussiness_profile.php? what=$1&type=$2&dealer=$3 [L]
rewriterule ^wholesale-parts/([^/\.]+)/?$ dealer_listings.php?territory=$1 [R=301,L]
rewritecond %{http_host} ^www.elite-dealers.com [nc]
rewriterule ^(.*)$ http://elite-dealers.com/$1 [r=301,nc]
RewriteRule ^(([^/]+/)*)index\.php http://elite-dealers.com/$1 [R=301,L]
Add the following code to your .htaccess file to redirect the ugly URL to the SEO friendly one.
#if the request is for dealer_listings
RewriteCond %{REQUEST_URI} ^/dealer_listings\.php$ [NC]
#and it has a territory parameter
RewriteCond %{QUERY_STRING} ^territory=([^&]+) [NC]
#then 301 redirect to the SEO friendly version
RewriteRule . wholesale-parts/%1/? [L,R=301]
I had a rule that redirect example.com > www.example.com.
I removed htaccess file and placed rules into a /etc/apache2/sites-available/example virtual host definition file. And basically rule above stopped working.
Here is the code, I would appreciate any help and it would be fun to know why the thing stopped working.
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/symfony/web
<Directory /var/www/symfony/web>
AllowOverride None
Allow from All
Options FollowSymLinks ExecCGI
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
You may want to just use Redirect in apache instead of messing with .htaccess. See my answer to a similar question.