Forum Moderators: phranque

Message Too Old, No Replies

htaccess in subdomain

htaccess in subdomain

         

orhhun

3:24 pm on Oct 26, 2008 (gmt 0)

10+ Year Member



i prefer to use htaccess file to make seo links in my site.
and last week, i started to make htaccess file for my subdomains.

i am using this code on my base directory of subdomain:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^folder/(.*) page.php?who=$1

i want this:
when i write: subdomain.site.com/folder/kelly
it must be opened: subdomain.site.com/page.php?who=kelly

but its not working fine with this code

there is an interesting point:
when i write the adress like this:
site.com/subdomain/folder/kelly = ok, its working with the code above
but if i write this:
subdomain.site.com/folder/kelly = its not working with the same code

do u have any idea about it? what must i do?
(my subdomanis are not fake)

g1smd

6:51 pm on Oct 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Does this example help?

[webmasterworld.com...]

That example is for two parameters so you can simplify it for your application.

orhhun

8:22 pm on Oct 26, 2008 (gmt 0)

10+ Year Member



thank you g1smd,

my english is not very vell; because of it, i couldnt understand well the content you show.

i changed my codes like this.. but it still dont work.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site\.com [NC]
RewriteRule ^folder/(.*) page.php?who=$1 [R=301,L]

when i write like this:
site.com/subdomain/folder/kelly = ok, its working
subdomain.site.com/folder/kelly = its not working with the same code

i want this:
when i write: subdomain.site.com/folder/kelly
it must be opened: subdomain.site.com/page.php?who=kelly

orhhun

7:53 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



isn't there someone having any idea about this problem?

could u help me to fix my code?

jdMorgan

12:07 am on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe you may need to put your code into the directory one level *above* the "base directory of subdomain" if you wish it to work when the "/subdomain" part of the URL is not present.

The problem may not be in the code. It may be that a request for your subdomain does not access the directory where this code is located. The .htaccess file must be in any of the directories in the requested URL-path in order to affect the request.

Jim

orhhun

9:09 am on Oct 28, 2008 (gmt 0)

10+ Year Member



my code is:
RewriteRule folder/(.*) page.php?who=$1
its in:
http://subdomain.examplee.com/.htaccess
and my request is:
http://subdomain.example.com/folder/kelly
and this request must open:
http://subdomain.example.com/page.php?who=kelly

if change the system like this:
RewriteRule (.*) ../page.php?who=$1
its in:
http://subdomain.example.com/folder/.htaccess
my new request:
http://subdomain.example.com/folder/kelly
and it must open: http://subdomain.example.com/page.php?who=kelly

in all way.... it doesn't work:(

[edited by: jdMorgan at 1:07 pm (utc) on Oct. 28, 2008]
[edit reason] Please use example.com [/edit]

jdMorgan

1:05 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your code is located in /folder/.htaccess, then you must not include "folder/" in the RewriteRule pattern.

In .htaccess, the directory path to the .htaccess file is removed by the server, so RewriteRule cannot "see" it. That is, the URL-path "seen" by RewriteRule in a .htaccess file is localized to that .htaccess file's directory.

In /folder/.htaccess, try:


RewriteRule (.*) page.php?who=$1 [L]

Jim

g1smd

1:10 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{HTTP_HOST} ^site\.com [NC] 

When the request is for a subdomain.site.com URL, this condition isn't met.

Am I right in thinking that you will also need a 301 redirect from site.com/folder and from www.site.com/folder over to subdomain.site.com too? Otherwise I can see at least 3 different ways for each "page" of content to be indexed.

jdMorgan

1:16 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, and likely several other canonicalizations as well. But we've got to get the posted problem sorted first... :)

Jim

orhhun

2:14 pm on Oct 28, 2008 (gmt 0)

10+ Year Member



htaccess is now in: http://subdomain.example.com/.thaccess

and the code is:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.example\.com [NC]
RewriteRule folder/(.*) http://subdomain.example.com/page.php?who=$1 [L,R=301]

still not working..

[edited by: jdMorgan at 3:34 pm (utc) on Oct. 31, 2008]
[edit reason] example.com [/edit]

g1smd

3:50 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not working for which URL requests?

example.com/subdomain/folder/name
www.example.com/subdomain/folder/name
subdomain.example.com/name
subdomain.example.com/folder/name

Note that your condition is testing that "example.com" was asked for, yet you said your request was for "subdomain.example.com"- so it will not match.

Your very first example was for a rewrite, but somehow it has now morphed into a 301 redirect which is something that I am sure is not what you require for that bit.

.

You need more than one rule here. I would have thought you would want a set of redirects to fix up the URL so that the right one displays, and then a rewrite to pull the content from the dynamic filepath without exposing the filepath. That's 3 or 4 steps, and to me it looks like the redirect code you have is for a mashup of step 3 and step 4, with a condition that applies in step 1 or 2.

In the example.com/.htacess file:

301 redirect example.com/subdomain to subdomain.example.com
301 redirect www.example.com/subdomain to subdomain.example.com
301 redirect all remaining example.com to www.example.com

In the subdomain.example.com/.htaccess (which is likely the same physical file as the example.com/subdomain/.htaccess file):

301 redirect example.com [1](we are in /subdomain folder)[/1] to subdomain.example.com
301 redirect www.example.com [1](we are in /subdomain folder)[/1] to subdomain.example.com
[b]Rewrite[/b] requests for folder/name to dynamic internal filepath (like your first example)

[edited by: jdMorgan at 3:37 pm (utc) on Oct. 31, 2008]
[edit reason] example.com [/edit]

orhhun

4:38 pm on Oct 28, 2008 (gmt 0)

10+ Year Member



in http://subdomain.example.com/.htaccess =

301 redirect example.com/subdomain subdomain.example.com
301 redirect www.example.com/subdomain subdomain.example.com
RewriteEngine on
RewriteRule ^folder/(.*) page.php?who=$1

its not working :( :( :( :(

the request must be = http://subdomain.example.com/folder/kelly
and this ruquest must go to http://subdomain.example.com/page.php?who=kelly

maybe u r explaning the wrong point; but i dont understand because of my english:( cant u write the corret code?

[edited by: jdMorgan at 3:39 pm (utc) on Oct. 31, 2008]
[edit reason] example.com [/edit]

jdMorgan

11:52 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



orhhun,

There are limits to what we can do for you. The purpose of this forum is not to serve as a free help desk. This is a discussion forum. It will be up to you to get your code working; We will be happy to help by answering very specific questions.

I suggest that you click on the "Forum Charter" link at the top left of this screen, and read the Apache mod_rewrite documentation and regular-expressions tutorial linked from our Forum Charter. If language is a problem, try searching for a translated version of the Apache documents -- They have been translated into many languages. You might also look for a "local expert" who can help you in your own language.

Reading and writing a foreign language is difficult, I know. Reading and writing about techincal subjects is almost impossible, so you're actually doing pretty well. :)

Also, if someone gives you some code to try, put it in the specified location exactly as given to you, instead of modifying it and putting it in a different location. People will lose interest in helping if you change the problem with every post...

Best,
Jim

orhhun

8:48 pm on Oct 29, 2008 (gmt 0)

10+ Year Member



dear jdmorgan,
thank you for your kind interest... in turksih forums, nobody could solve this problem.

actually the problem is the same. i need a htaccess code for this.
http://subdomain.example.com/folder/kelly =>>>> http://subdomain.example.com/page.php?who=kelly

all the codes i tried, did not solve the problem. (i wrote above all the codes i tried)

[edited by: jdMorgan at 3:40 pm (utc) on Oct. 31, 2008]
[edit reason] example.com [/edit]

jdMorgan

2:11 pm on Oct 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try the code I posted in message #:3774976 above in the .htaccess file location that I specified?

Jim

orhhun

9:48 am on Oct 31, 2008 (gmt 0)

10+ Year Member



yes. but didn't work..

in http://subdomain/example.com/folder/.htaccess
RewriteEngine on
RewriteRule (.*) page.php?who=$1 [L]

and also i tried this too(page.php is not in "folder/" its in the base/root directory of subdomain)
RewriteEngine on
RewriteRule (.*) ../page.php?who=$1 [L]

[edited by: jdMorgan at 3:41 pm (utc) on Oct. 31, 2008]
[edit reason] example.com [/edit]

jdMorgan

2:58 pm on Oct 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If page.php is not located in /folder, you may need
in http://subdomain/example.com/folder/.htaccess :

RewriteEngine on
RewriteRule (.*) [b]/pa[/b]ge.php?who=$1 [L]

Or alternately, in http://subdomain/example.com/.htaccess :

RewriteEngine on
RewriteRule ^[b]folder/[/b](.*)$ /page.php?who=$1 [L]

If neither of these work, and there is nothing in your server error log that indicates differently, then it is likely that the way in which your control panel configures subdomains will not allow "crossing over" from the subdomain's filespace to the main domain's filespace.

Jim

orhhun

9:13 am on Nov 4, 2008 (gmt 0)

10+ Year Member



so; do u have any idea that; how can i allow/control the crossing over function on apache?

jdMorgan

11:52 am on Nov 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, edit httpd.conf and/or conf.d, point all subdomains to the same DocumentRoot as the main domain, and then modify the existing redirect/rewrite code in httpd.conf and .htaccess so that it checks and handles the subdomain requests appropriately.

Be careful never to use the control panel "add-on domain" commands after doing this, as the control panel script may break your config file changes.

Jim