Welcome to WebmasterWorld Guest from 54.196.247.143

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

wildcard sub domains

wilcard sub domains with pass more parameters

     

kawdo

2:55 pm on Aug 7, 2010 (gmt 0)

5+ Year Member



dear all , i am confusing with wildcard subdomain and i hope your help

I have wildcard subdomains setup and working great.
The only problem is I can't get htaccess to see anything else like subdomain.example.com/profile/some_name/some_id_number/.
In fact, I can type any garbage after the domain and it will still just show me the home screen.


see for exsample ,

http://2072.landsale.lk/fsdfsdfsdfsd.php
http://2072.landsale.lk/fsdfsdfsdfdsfsdfsdfsdrwerwefsd.php
http://2072.landsale.lk/fsdf432423423b5234234v23423sdfsdfsd.php
http://2072.landsale.lk/fsdfsdfsdfsd.html
http://2072.landsale.lk/fsdfsdfdas3423423sdfsd.php

all pages , what ever , any page go to same index file , why is that , why cannot make different pages on this example subdomain


this is my httaccess file

RewriteCond %{HTTP_HOST} ^www\.landsale.lk
RewriteCond %{QUERY_STRING} ^name=(.*)$
RewriteRule .* http://%1.landsale.lk? [R=301,L]
#
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
#
RewriteCond %{HTTP_HOST} !^www\.landsale.lk
RewriteCond %{HTTP_HOST} ([^.]+)\.landsale.lk
RewriteRule ^(.*)$ /mydanweem\.php?name=%1 [L]

i am waiting for your help....

[edited by: jdMorgan at 2:31 pm (utc) on Aug 10, 2010]
[edit reason] Formatting for readability [/edit]

jdMorgan

3:08 pm on Aug 10, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Correcting some problems, and making this code more robust and efficient gives:

# Externally redirect direct client requests for /mydanweem.php script URL to "user" subdmomain URL
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /mydanweem\.php\?([^&#\ ]&)*name=([^&#\ ]+)[^\ ]*\ HTTP/
RewriteRule ^mydanweem\.php$ http://%2.landsale.lk/? [R=301,L]
#
# Internally rewrite subdomain URL requests to the /mydanweem.php script
# filepath with "name=" query string, unless this has already been done
RewriteCond %{HTTP_HOST} !^www\.landsale\.lk [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.landsale\.lk
RewriteRule !^mydanweem\.php$ /mydanweem\.php?name=%1 [L]

Note the comments. You will gain much productivity and happiness by commenting your code concisely and accurately.

More notes:

I have modified the "infinite loop" prevention of your code by using THE_REQUEST in the first rule, and by excluding the /mydanweem.php filepath in the second rule.

The first rule no longer cares about the requested hostname, and is therefore more robust. That is, it will 'correct' requests for /mydanweem.php?name=<user> no matter what hostname that request is sent to. It will also do this even of there are other "extra" query string parameters present.

In the second rule, a request for "http://user.landsale.lk/somthing-here" will be rewritten to "/mydanwweem.php?name=user" and the "something-here" URL-path-part will be "lost." If needed, the script will have to get that path-part from a server variable.

Any query strings appended to user.landsale.lk/ URLs will also be "lost" as this rule presently coded. That may or may not be what you want.

Finally, consider whether you really want to rewrite *all* requests to your script; It is usual to exclude requests for objects such as images, css stylesheets, external JavaScripts, documents, and multimedia files which are shared between "users," and just let the server serve those directly.

Jim

[edit] Corrections as noted below. [/edit]

[edited by: jdMorgan at 4:52 pm (utc) on Aug 12, 2010]

kawdo

5:13 am on Aug 11, 2010 (gmt 0)

5+ Year Member



But

for ex :

this is not redirect

[landsale.lk...]

for

[2072.landsale.lk...]


another question , [2072.landsale.lk...] this will give 500 internal error.

waiting for your reply

phranque

7:33 am on Aug 11, 2010 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



this will give 500 internal error

check your server error log.

kawdo

7:46 am on Aug 11, 2010 (gmt 0)

5+ Year Member



visit this link [2072.landsale.lk...]

phranque

7:58 am on Aug 11, 2010 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



visiting that link will only verify that a 500 status code response was supplied.
visiting the server error log will give you a clue about what caused the 500 Internal Server Error.

jdMorgan

5:00 pm on Aug 12, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Well, first correct my mis-spelling of "mydanweem" as "mydanwee" -- That is likely to cause at least one problem. See the corrected code above.

Jim

kawdo

5:42 am on Aug 20, 2010 (gmt 0)

5+ Year Member



Yes jdMorgan, Your code is working, but can i pass two variables to wild card sub domain like this

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /mybrowse\.php\?([^&#\ ]&)*name=([^&#\ ]+)[^\ ]&fatherID=([^&#\ ]+)[^\ ]*\ HTTP/
RewriteRule ^mybrowse\.php$ http://%1.sriauto.com/sri-lanka-classifieds-%2\.html? [R=301,L]


this is not working for me . pls help , all URLs go to index page as your code .

jdMorgan

12:38 pm on Aug 20, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If you do not understand the regular expressions patterns, then do not attempt to modify code. The nature of mod_rewrite+regular expressions is that the code and the patterns must be precisely correct. If not, it will never work, and there is no "guessing" to this at all. One must "know." See the resources cited in our Apache Forum Charter for more information.

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /mybrowse\.php\?([^&#\ ]&)*name=([^&]+)&fatherID=([^&#\ ]+)[^\ ]*\ HTTP/
RewriteRule ^mybrowse\.php$ http://%1.sriauto.com/sri-lanka-classifieds-%2\.html? [R=301,L]

You will also need another new rule to internally rewrite requests for these "classifieds" friendly URLs to your script, passing both parameters in the query string.

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month