Forum Moderators: phranque

Message Too Old, No Replies

subdomain and url rewriting (again plz)

the requested URL was not found

         

cyberlahy

5:57 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



hello,

I've search since the last week the problem but I never see the solution (I'm a newbie).

I'm in shared hosting but I can create unlimited subdomains from CPanel and PHP/CPanel.

I create aaa.mydomain.com and bbb.mydomain.com
And I want to have www.mydomain.com/show.php?user=aaa&page=abc

But when I do aaa.mydomain.com/abc.html the message is :
Not Found
The requested URL /index.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

And when I do aaa.mydomain.com, I have the directory

My htaccess is

RewriteEngine on

# If www domain requested, rewrite html page requests to show.php with
# query string
RewriteCond %{REQUEST_URI}!^/show\.php
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com
RewriteRule ^([^.]+)\.html /show.php?page=$1 [L]
#
# If www domain requested, rewrite home page requests to show.php
# with query string page = "home"
RewriteCond %{REQUEST_URI}!^/show\.php
RewriteCond %{HTTP_HOST} ^www\.mydomain.com
RewriteRule ^$ /show.php?page=home [L]
#

# If subdomain requested, rewrite subdomain and html page requests
# to index.php with query string
RewriteCond %{REQUEST_URI}!^/index\.php
RewriteCond %{HTTP_HOST}!^www\.mydomain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com
RewriteRule ^([^.]+)\.html /index.php?user=%1&page=$1 [L]
#
# If subdomain requested, rewrite home page requests to index.php
# with query string user=subdomain & page="home"
RewriteCond %{REQUEST_URI}!^/index\.php
RewriteCond %{HTTP_HOST}!^www\.mydomain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com
RewriteRule ^$ /index.php?user=%1&page=home [L]

What's wrong?

Thanks
Cyberlahy
Madagascar

Excuse my bad english

jdMorgan

12:22 am on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cyberlahy,

Welcome to WebmasterWorld!

It is very often the case that "subdomains" created with cPanel are created as separate subdirectories below the original Web root directory. These subdomain/subdirectories cannot 'see' any directories above them. Therefore, the domain-related part of your code would need to be copied (or symlinked) into those new subdirectories.

Also, do you have *any* rewriterules that work? If not, add
Options +FollowSymLinks
at the top of your mod_rewrite code.

Jim

cyberlahy

1:17 pm on Apr 9, 2006 (gmt 0)

10+ Year Member



Thank you very much Jim,

I put file.php in each subdirectories and this file have PHP code include( "../file.php" ).

url rewrite works thanks.

But I have another problem :

# If www+subdomain domain requested, externally redirect to subdomain without "www"
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.mydomain\.com
RewriteRule (.*) h**p://%1.mydomain.com/$1 [R=301,L]
#

and when I do : www.aaa.mydomain.com or www.aaa.mydomain.com/azerty.html it's return in my browser :
aaa.mydomain.com/aaa or
aaa.mydomain.com/aaa/azerty.html

Another question when I do aaa.mydomain.com or bbb.mydomain.com/azerty.html or anySubDomain.mydomain.com, they work well but one subdomain ccc.domain.com return mydomain.com/ccc

Even when I remove this subdomain and subdirectory and recreate it, it's return the same.
Even when I leave empty the htaccess

What file can redirect this subdomain like that?

And when I see my CPanel, there is no redirect.

All my thanks again to you Jim for your explanation at [webmasterworld.com ]

jdMorgan

1:22 pm on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a problem of rule order.

Put the www.<sub>.domain.com redirect rule first.
Then put the <sub>.domain.com redirect rule next.
Lastly, do the internal rewrite from <sub>.domain.com to /sub

If you put the rewrite before the redirects, then the redirects will 'expose' the rewritten script URL.

Jim

cyberlahy

3:47 pm on Apr 10, 2006 (gmt 0)

10+ Year Member



Hello Jim,

The order of my rewrite rule is like that.
But if i leave empty my htaccess, it's the same result.

www.aaa.mydomain.com -> aaa.mydomain.com/aaa
www.aaa.mydomain.com/abc.html -> aaa.mydomain.com/aaa/abc.html

And the problem of only one subdomain ccc
if I do ccc.mydomain.com -> mydomain.com/ccc

but when I do aaa or bbb or ddd.mydomain.com they stay ddd.mydomain.com

Even htaccess empty.