logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: alias.domain rewrite, redirect or something.
Author
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Sat 20 Dec '14 19:30    Post subject: alias.domain rewrite, redirect or something. Reply with quote

Apache version 2.2.14 (ubuntu 10.04)

I need to redirect my domain

<VirtualHost 192.168.1.3:80>
ServerName domain.com
ServerAlias www.domain.com
ServerAlias alias.domain.com
</VirtualHost>

I need to tell the server to redirect from:
http://alias.domain.com
to
http://www.domain.com/shopping

(and/or how would it to 'forward' to a shopping.php page?)

I cannot make it work without endless looping!

KW
Embarassed
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Sat 20 Dec '14 23:10    Post subject: Reply with quote

Hi,

it is easy to do

Code:
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Back to top
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Sun 21 Dec '14 2:23    Post subject: fail Reply with quote

RewriteBase: only valid in per-directory config files
...fail!

Thanks but your example is the same as the MANual. (and too hard for me to de-code with any success).

I tried:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^fancyalias\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/shopping/$1 [R=301,L]



Can you please translate more specific to my request, please. I do naught understand the $1


my need:

from:
alias.domain.com

to:
www.domain.com/shopping.php

or:
www.domain.com/shopping/
Back to top
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Sun 21 Dec '14 23:21    Post subject: Stucked & No Worky Reply with quote

Stucked & No Worky
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Mon 22 Dec '14 11:35    Post subject: Reply with quote

Code:

RewriteEngine On
# if the host is NOT (!) www than rewrite the stuff
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
# get everthing from the URL and append it where the $1 is
RewriteRule ^(.*)$ http://www.mydomain.com/shopping/$1 [R=301,L]
Back to top
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Tue 23 Dec '14 7:16    Post subject: success! Reply with quote

I deleted the $1 and it works as I wush.
I still don't know what the $1 is for.

I can do both /shopping with an index.page there, and /shopping.php with much success!

The unknown factor is what that $1 does as it appended two slashes afta shopping//

Love You Apache Boys for rescuing lil ol' me and mine
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Tue 23 Dec '14 10:38    Post subject: Re: success! Reply with quote

karenwood wrote:

I still don't know what the $1 is for.


Well

if

sudomain.example.com/lorem_ipsum?some=123
it will become
http://www.example.com/shoppping/lorem_ipsum?some=123 Wink
Back to top
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Thu 15 Jan '15 23:47    Post subject: working but presents new problem Reply with quote

alias.domain.com/shopping/index.php works as I was hoping for expected:

Code:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/shopping/index.php [R=301,L]


BUT I now find that any directory redirects so, domain.com/otherdirectory redirects too! (no www.domain.com or alias.domain.com)

please reply, thank you!
Back to top
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Sat 17 Jan '15 12:34    Post subject: solved one problem -caused another!!! Reply with quote

Please help!

Although the domain.com/shopping/index.php works according to the .htaccess directive, now ANY DIRECTORY also reditects!!!

I must ONLY redirect the shopping directory not EVERY directory.

Please respond, thank you!!!!!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Sat 17 Jan '15 23:11    Post subject: Reply with quote

You can put that rewrite rule into a directory block or move the .htaccess file in to the shopping folder
Back to top
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Tue 03 Feb '15 22:37    Post subject: no no no no no! Reply with quote

Every Directory Redirects.

http://aliasword.domain.com/about also redirects >which is BAD<
http://aliasword.domain.com/help also redirects >which is BAD<


I only want to redirect the one specific aliasword i.e: http://aliasword.domain.com/shopping

My .htaccess file as is:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/shopping/index.php [R=301,L]

frustrating.

Please, can someone provide the solution to:
redirect only http://aliasword.domain.com to the directory http://aliasword.domain.com/shopping/index.php as a rule for the .htaccess which will ONLY redirect that specific aliasword
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Wed 04 Feb '15 14:13    Post subject: Reply with quote

OMG ...you've even got this dumb guy from down the coast confused.

The last line of your last post reads aliasword.karensdomain.com -> aliasword.karensdomain.com/shopping/index.php

Way up above you claim you want aliasword.karensdomain.com -> www.karensdomain.com/shopping/index.php

Which is it?

My other maybe more important question is, if I go to simply www.karensdomain.com where do you want me to land then? This will help me decide if you even really need rewriting.

But let's back up a little and scratch our heads. What you have there says: If the hostname does not match www.karensdomain.com then do stuff. To be honest, I do not think before time ends and only machines roam the earth aliasword.karensdomain.com is ever going to match www.karensdomain.com and probably not even then. What do you think? If you agree, then I suppose that condition needs to be tossed into the La Brea tar pit because the rule then is always going to fire for anything not www.karensdomain.com, you know, like http://aliasword.karensdomain.com/help.

So I think you want to hone in on only aliasword.karensdomain.com instead, but remember, I'm confused!

RewriteCond %{HTTP_HOST} ^aliasword\.karensdomain\.com$ [NC]

of course that still leaves the problem of likely barfing up on things like http://aliasword.karensdomain.com/about and friends so maybe add a caveat after it

RewriteCond %{REQUEST_FILENAME} !-d

I must admit I am not a URL Rewriting wiz though, it's an art form I have not come close to mastering sadly.
Back to top
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Fri 06 Feb '15 22:44    Post subject: Reply with quote

need:

www.KARENSDOMAIN.com >>goto index.php
nothing_here_before.KARENSDOMAIN.com/regular_old_index.php page

DumbWord_alias.KARENSDOMAIN.com/Regular_old_INDEX.PAGE.PHP

SPECIALWORD_ALIAS.KARENSDOMOAIN.com/shopping/index.php

pretty please...

Sincerely,
Karen
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sat 07 Feb '15 11:06    Post subject: Reply with quote

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ^specialword_alias\.karensdomain\.com$ [NC]
RewriteRule .? /shopping/index.php [R=301,L]

Does this not do what you're looking for?

This should not affect
karensdomain.com
www.karensdomain.com
dumbword_alias.karensdomain.com
so all the above should just go to what is set for the DirectoryIndex, which I assume is index.php

It should also not affect
specialword_alias.karensdomain.com/some_other_existing_file_or_folder Smile
Back to top
karenwood



Joined: 20 Dec 2014
Posts: 9
Location: USA, Ventura

PostPosted: Sun 08 Feb '15 5:41    Post subject: successssssssssss! Reply with quote

Very Happy
¡muchas gracias!
!thank you mooie muchas!
Embarassed
Back to top


Reply to topic   Topic: alias.domain rewrite, redirect or something. View previous topic :: View next topic
Post new topic   Forum Index -> Apache