homepage Welcome to WebmasterWorld Guest from 184.73.72.163
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
wildcard sub domains
wilcard sub domains with pass more parameters
kawdo




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

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




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

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




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

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




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

this will give 500 internal error

check your server error log.

kawdo




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

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

phranque




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

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




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

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




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved