htaccess redirect subfolder - .htaccess

I would like to redirect the url http://intranet/trac/paradox/report/6 to http://cobra.woking/trac/paradox/report/6. trac is a subfolder and paradox is a subfolder. report/6 are params that need to be kept and may change.
In my apache doc root i have
#/opt/html/.htaccess
Redirect 301 / http://intranet/intranet
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]
I have tried the following which does not work
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
URL i want to change is http://intranet/trac/paradox/ to http://cobra.woking/trac/paradox/. I have placed .htaccess in the /opt/html/trac/paradox/.htaccess

In the htaccess file of your intranet's document root, add this to the top of the file:
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]

Related

How to hide .htaccess redirect from user

I have server with domain www.domain.com and multiple sub domains sub1.domain.com, sub2.domain.com. They are all pointing to server root.
I'd like users to access specific folders by subdomains. For example:
sub1.domain.com/someURI => sub1.domain.com/subFolder1/someURI
sub2.domain.com/someURI => sub1.domain.com/subFolder2/someURI
I would like to hide these redirections from users. I tried following .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub1.domain.com$
RewriteRule ^(.*)$ http://sub1.domain.com/subFolder1/$1 [R,L]
RewriteCond %{HTTP_HOST} ^sub2.domain.com$
RewriteRule ^(.*)$ http://sub2.domain.com/subFolder2/$1 [R,L]
It is redirecting correctly only without any URI and redirection is visible.
You have 2 issues that are causing external redirect:
Using R flag in RewriteRule
Using Absolute URL starting with http:// in target
Another issue is that your rewrite rule is unconditional which can cause infinite looping.
You can use these rules:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} =sub1.domain.com
RewriteRule ^((?!subFolder1/).*)$ subFolder1/$1 [NC,L]
RewriteCond %{HTTP_HOST} =sub2.domain.com
RewriteRule ^((?!subFolder2/).*)$ subFolder2/$1 [NC,L]

Htaccess rewrite in subfolder with parameters

I'm trying to rewrite /streams/post.php?id=1 into /streams/thread/1 .
I did find some codes for .htaccess with parameters but it didn't work in the subfolder.
Also, should I put another .htaccess in the subfolder or use the one on the main directory? ( /.htaccess or /streams/.htaccess)
Also, in the past when I've rewritten, sometimes it redirects from for example /streams/thread/1 to /streams/post.php?id= and sometimes it actually displays /streams/thread/1 in the URL, I would like it to display /streams/thread/1 in the URL, not just redirect.
You can put your htaccess in root or streams folder (that's up to you).
In root folder
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/streams/post\.php\?id=([0-9]*)\s [NC]
RewriteRule . streams/thread/%1? [R=301,L]
RewriteRule ^streams/thread/([0-9]+)$ streams/post.php?id=$1 [L]
In streams folder
RewriteEngine On
RewriteBase /streams/
RewriteCond %{THE_REQUEST} \s/streams/post\.php\?id=([0-9]*)\s [NC]
RewriteRule . thread/%1? [R=301,L]
RewriteRule ^thread/([0-9]+)$ post.php?id=$1 [L]

301 redirecting a rewritten URL

I'm attempting to redirect some rewritten URL's but while the redirect is working, it is including the original parameter before the rewrite.
e.g. Redirect /used-cars.html http://www.odins.co.uk/our-cars.html
The rewritten URL is based upon the following structure:
http://www.domain.co.uk/pages/index.php?p=used-cars
However, what is happening is this:
http://www.domain.co.uk/our-cars.html?p=used-cars
The .htaccess file is as follows:
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^odins.co.uk [NC]
RewriteRule ^(.*)$ http://www.odins.co.uk/$1 [L,R=301]
RewriteRule ^([^/]*)\.html$ /pages/index.php?p=$1 [L]
RewriteRule ^news/([^/]*)$ /pages/news/index.php?n=$1 [L]
Redirect /used-cars.html http://www.domain.co.uk/our-cars.html
Any help would be appreciated.
Paul

htaccess mod_rewrite .tld to specific folder

I want to do the following, if possible, with htaccess.
The webpage works this way, you get the index file via domain.de/de/start and the english version via domain.de/en/start.
If a user visits domain.com I would like him to end up at domain.de/en/ instead of domain.de/de/ so I need to rewrite all requests to domain.com but NOT requests with domain.com/xx/something to domain.de/en/
Thanks.
If I understand you clearly you only want to redirect http://domain.com/ to http://domain.de/en/ but do NOT want to redirect http://domain.com/XX/YY
Put this code in your .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^$ http://domain.de/en/ [L,R=301]
Try to use HTTP_HOST and rewritecond
RewriteCond %{HTTP_HOST}=domain.de
RewriteCond %{REQUEST_URI}=/ % redirect only the root
RewriteRule ^/$ /de/start [L] % to /de/start
RewriteCond %{HTTP_HOST}=domain.de
RewriteCond !%{REQUEST_URI}=/ % no root
RewriteCond !%{REQUEST_URI}=/[a-z]{2}/.* % except /xx/ directories
RewriteRule ^/.*$ /de/$1 [L] % push the user in the /de/ directory

Redirect specific page with query using htaccess

for example
mydomain.com/jobresultpage?what=&where=Arkansas
redirect to
yourdomain.com/jobresultpage?what=&where=Arkansas
but other page like
mydomain.com/about.html
mydomain.com/contact.html
not redirect..
Try adding the rules below to the .htaccess file located in the root directory of mydomain.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} mydomain\.com$ [NC]
#redirect any request for jobresult to yourdomain
RewriteRule ^jobresultpage$ http://yourdomain.com%{REQUEST_URI} [NC,L,R=301]

Resources