I need to redirect from abc.com/param to test.bcd.com/?query=param via htaccess.
Is it correct?
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?test\.bcd\.com$ [NC]
RewriteRule .* http://test.bcd.com/?query=%{REQUEST_URI} [R=301,L]
Please try this
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^query=param [NC]
RewriteCond %{HTTP_HOST} !^(www\.)?test\.bcd\.com$ [NC]
RewriteRule ^ http://test.bcd.com%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
for redirect to index.html then try this
Please add following two lines to allow a specific file to load just in case there is no default index file setup already
Options -Indexes
DirectoryIndex index.html index.php
Note : if you have to load first php index file then you have set like
DirectoryIndex index.php index.html
Related
I work local on my machine. I have some problems with redirect through .htaccess. In my web-application I have 2 redirect through 2 .htaccess files.
I have next structure my app:
root:
application (dir)
public (dir)
index.php
.htaccess
.htaccess
In first .htaccess file has next code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$ [L]
</IfModule>
but it doesn't work. In browser I see next picture view in browser
I change file apach2.conf and add
<Directory /var/www/my-site/>
AllowOverride All
</Directory>
but it don't help fix problem.
What I must do to it work?
Try this :
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]
I have problem with .htaccess.
I need:
if $_SERVER["HTTP_HOST"] is sub.site.com must show content from www.site.com/sub/. But URL must be like sub.site.com.
And if sub.site.com/content/ must show content from www.site.com/sub/content/
Is it Possible?
Setting subdomains from hosting not working for me because of my CMS.
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.site.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -d
RewriteRule ^(.*)$ /sub/$1 [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 %{HTTP_HOST} ^sub\.site\.com$ [NC]
RewriteRule (?!^sub/)^(.*)$ /sub/$1 [L,NC]
My folder for public_html is /domain.com/public_html/ but i want the htaccess to redirect them to the folder /domain/public_html/www/ but still have domain.com as domain and not domain.com/www .
EDIT:
I want the subfolder www in the public_html do be the default root and not public_html itself
Any solution on this?
Here is my current htacess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
If you can only go for .htaccess, this simple one should do it;
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ /www/$1 [QSA]
Explanation;
RewriteEngine on # Turn on mod_rewrite functionality
RewriteCond %{REQUEST_URI} !^/www/ # Don't rewrite requests that are
# already to the /www/ directory.
# If this isn't here, we'll go into
# a neverending loop.
RewriteRule ^(.*)$ /www/$1 [QSA] # Rewrite all else to the www subdirectory
# QSA = keep the query string.
EDIT: Didn't see your existing htaccess, this (minus the redundant RewriteEngine statement) should probably go at the end instead of the whole IfModule block.
Try to put this in the htaccess on the public_html folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
OR
Edit the apache configuration (httpd.conf)
vi /usr/local/apache/conf/httpd.conf
and set the DocumentRoot of the domain as
DocumentRoot /home/user/public_html/www
Save the file and restart the httpd service.
OR (recomanded)
Take a look at this question(and it's answer) - https://stackoverflow.com/a/5891858/1361042
EDIT
Use this HTACCESS:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ www/$1 [NC, QSA]
</IfModule>
don't add it to yours but replace your htaccess with this one.
i need help redirecting this two links to one link:
Link #1: http://www.domain.com/index.php?til=d_news&id_new=1
Link #2: http://www.domain.com/new_folder/?til=d_news&id_new=1
need to redirect to:
http://www.domain.com/news/news.html
i tried using this code:
RewriteCond %{QUERY_STRING} ^til=d_news
RewriteRule ^(.*)$ http://%{HTTP_HOST}/news/news.html? [R=301,L]
but it only redirects the first link and not the second.
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} ^til=d_news&id_new=1 [NC]
RewriteRule ^ /news/news.html? [R=301,L]
In the htaccess file in your document root, add:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1
RewriteRule ^index.php$ /news/news.html? [L,R=301]
RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1
RewriteRule ^new_folder/?$ /news/news.html? [L,R=301]
In your second link there is no destination page:
http://www.domain.com/new_folder/?til=d_news&id_new=1
should be something like:
http://www.domain.com/new_folder/page.php?til=d_news&id_new=1
I have a shared hosting with one domain and one sub-domain (for mobile and clients). Each domain and sub-domains has different default index pages. The hosting company told me to put everything in my .htaccess file since I don't have access to the httpd.conf.
What I want to do is this:
If a user goes to domain1.com the DirectoryIndex should be: index.html
If a user goes to mobile.domain1.com the DirectoryIndex should be: mobile-index.html
If a user goes to post.domain1.com the DirectoryIndex should be: post.php
If a user goes to vote.domain1.com the DirectoryIndex should be: vote.php
Edit:
In addition, if I go to domain1.com/page/ the DirectoryIndex should be: index.html. If I go to mobile.domain1.com/page/ the DirectoryIndex should be: mobile-index.html
What can I put in my .htaccess file in order to change the DirectoryIndex for each sub-domain?
Thank You very mich
<IfDefine> does not work like that. <IfDefine> only runs when apache starts. You should go with a mod_rewrite solution. view #tzakrajs answer.
You can use this in your .htaccess file:
SetEnvIf Host ^www\. page=www
SetEnvIf Host ^mobile\. page=mobile
rewriterule ^.*$ test.php?subdomain=%{ENV:page} [QSA,L]
Simply just configure all your sub-domain using SetEnvIf and then simply let the PHP do its magic.
Try this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule ^.*/$ index.html [R=302,L]
RewriteCond %{HTTP_HOST} ^mobile.domain1.com$
RewriteRule ^.*/$ mobile-index.html [R=302,L]
RewriteCond %{HTTP_HOST} ^post.domain1.com$
RewriteRule ^.*/$ post.php [R=302,L]
RewriteCond %{HTTP_HOST} ^vote.domain1.com$
RewriteRule ^.*/$ vote.php [R=302,L]
You can set using just oyur .htaccess file like this:
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteRule DirectoryIndex index.html
RewriteCond %{HTTP_HOST} ^mobile.domain.com$ [NC]
RewriteRule DirectoryIndex mobile-index.html
...