redirect to a new folder

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

redirect to a new folder

Postby deaa13 » Wed Feb 11, 2009 4:49 pm

Hello,

I want to do the following:
when someone enter my domain to redirect it to dummy url.

for example when enter -www.example.net or -www.example.com (I have net & com)

to change the url to -www.example.net/online/

online folder doesn't exist

How to do it in mod rewrite ??

thank you
deaa13
 
Posts: 3
Joined: Wed Feb 11, 2009 4:45 pm

Advertisement

Postby SeO » Thu Feb 12, 2009 5:29 pm

Why not using the domain's root level in the first place ?

It's not very good to, IMHO, use a sub directory when the above level is free to use.
Even if you plan to later add something in the domain's root level, you should start right now, even with few pages to start building PageRank on the domain's root level.

Now, about redirecting the .net to the .com, and assuming both share the same dns and vhost settings (eg they lead to the same place), just use the www prefix redirection (method n°2), it will additionaly make sure you use the www prefix.

If you really want to redirect the root level to the online/ dir, you can use something like :
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /online/$1 [QSA,L,R=301]


after the www prefix redirection.
SeO
Admin
Admin
 
Posts: 6333
Joined: Wed Mar 15, 2006 9:41 pm

Postby deaa13 » Thu Feb 12, 2009 10:35 pm

Thank you for the reply

but it didn't work...

I will explain myself. I need online directory for google adsense optimization, I will use a better word, so the relevant ads will be more efficient.

online directory is fake one, it's not exist..

I want to do something like this:

when enter -www.example.net it will show -www.example.net/online/ instead.

and when entering:
-www.example.net/index.php?id=4

it will show: -www.example.net/online/index.php?id=4

it just to add the fake online

thank you
deaa13
 
Posts: 3
Joined: Wed Feb 11, 2009 4:45 pm

Postby SeO » Fri Feb 13, 2009 8:06 am

It does not really matter if the dir is virtual mod_rewrite wise, but again, I'm wondering about the positive effect of such technique, think of this this way :
will all your site be focused on the "online" keyword ?
wouldn't it be more reasonable to use it on really related page and then use other keywords for other pages ?

Page titles and meta tags are important too for AdSense, but I don't think repetition is the wisest in the matter, relevancy is better.
SeO
Admin
Admin
 
Posts: 6333
Joined: Wed Mar 15, 2006 9:41 pm

Postby deaa13 » Fri Feb 13, 2009 4:43 pm

because my website is not in english, so any word I can add , will be very vital. and the best place is the website URL then the title... I handled the title but trying now to do a change in my URL format and to include a word or two which can help me. (it helpful because I notice a new adsense ads which relevant to the word I choose).


But I still trying to figure it.

it seems your suggestion has a lack.

Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /online/$1 [QSA,L,R=301]


when I tried :www.example.net/index.php?id=4 it didn't forward to
-www.example.net/online/index.php?id=4

and the same for the main URL -www.example.net (I want it to redirect to -www.example.net/online/)


BTW I succeeded to do the following:
example.net , example.com and -www.example.com redirected to :
-www.example.net/online/

I used this code:
Code: Select all
RewriteCond %{HTTP_HOST} !^(.*)\.example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.net/online/$1 [R=301,L]

RewriteRule ^online/(.*) /$1

and all the sub urls became relative to online/ which is perfect to me


but still -www.example.net
deaa13
 
Posts: 3
Joined: Wed Feb 11, 2009 4:45 pm

Postby SeO » Fri Feb 13, 2009 7:08 pm

what about :
Code: Select all
RewriteCond %{HTTP_HOST} !^(.*)\.example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.net/online/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /online/$1 [QSA,L,R=301]
RewriteRule ^online/(.*) /$1 [QSA,L,NC]
SeO
Admin
Admin
 
Posts: 6333
Joined: Wed Mar 15, 2006 9:41 pm

Re:

Postby Horizon70s » Tue Dec 01, 2009 8:52 pm

This is a great example below, but it only works for me if they enter example.com/..... and not if they come with -http://www.example.com/......

Any suggestions?

SeO wrote:what about :
Code: Select all
RewriteCond %{HTTP_HOST} !^(.*)\.example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.net/online/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /online/$1 [QSA,L,R=301]
RewriteRule ^online/(.*) /$1 [QSA,L,NC]
Horizon70s
 
Posts: 32
Joined: Wed Jan 21, 2009 4:06 pm

Re: redirect to a new folder

Postby Horizon70s » Thu Dec 03, 2009 3:27 pm

I've tried the following below in addition to the example above, but I still can't handle the www redirect for topics. Am I on the right path?

Code: Select all
RewriteCond %{HTTP_HOST} !^(.*)www\.example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.net/online/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /online/$1 [QSA,L,R=301]
RewriteRule ^online/(.*) /$1 [QSA,L,NC]
Horizon70s
 
Posts: 32
Joined: Wed Jan 21, 2009 4:06 pm

Re: redirect to a new folder

Postby dcz » Sat Dec 05, 2009 10:05 am

Code: Select all
RewriteCond %{HTTP_HOST} !^www\.example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.net/online/$1 [R=301,L]
RewriteRule ^(?!online)(.*)/?$ /online/$2 [QSA,L,R=301]


?
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Re: redirect to a new folder

Postby Horizon70s » Mon Dec 07, 2009 7:42 pm

I'm moving our forum from the root to a subdirectory /forum/ .

At the root is going to be a CMS program for articles, news, etc. So I don't want everything to redirect including the index, just the forums and topics.

www.example.net/viewtopic# to -http://www.example.net/forum/viewtopic#

OR
example.net/viewtopic# to example.net/forum/viewtopic#

-http://www.example.net/viewforum# to -http://www.example.net/forum/viewforum#

OR
example.net/viewforum# to example.net/forum/viewforum#


The code below works for non-www redirects, but not those with www links. I wanted to have everything redirect before we go live with the change.

Code: Select all
RewriteCond %{HTTP_HOST} !^(.*)\.example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.net/online/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /online/$1 [QSA,L,R=301]
RewriteRule ^online/(.*) /$1 [QSA,L,NC]
Horizon70s
 
Posts: 32
Joined: Wed Jan 21, 2009 4:06 pm

Re: redirect to a new folder

Postby Horizon70s » Wed Dec 09, 2009 3:41 pm

Nevermind, we went live anyways...but thanks for the previous help.
Horizon70s
 
Posts: 32
Joined: Wed Jan 21, 2009 4:06 pm


Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 3 guests