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

Apache Web Server Forum

    
Help with rewrite cond
rwrite condition
ivanvias




msg:4131775
 3:00 am on May 13, 2010 (gmt 0)

Hi,

I need some help with some rewrite condition. I have the following url:http://www.example.com/com/mem/site/43


Which i'd like to narrow down to http://www.example.com/43.


How do i write this in my htaccess file?

 

jdMorgan




msg:4131779
 3:16 am on May 13, 2010 (gmt 0)

Please post your best-effort attempt at coding this, as a basis for discussion.

Please review our Forum Charter for more information.

When re-posting, please specify the current URL, the new URL, and the actual server filepath -- all three are needed to make sense of this kind of function.

Thanks,
Jim

ivanvias




msg:4131783
 3:20 am on May 13, 2010 (gmt 0)

Okay,

I need to get allow these http://www.example.com/43 to work as http://www.example.com/com/mem/site/43

And show on browser as http://www.example.com/43


RewriteBase /

RewriteCond $1 !^administrator
RewriteCond $1 !^faq[OR]
RewriteCond $1 !^features[OR]


ewriteRule ^([A-Za-z-]+)/?$ com/mem/site/$1 [NC,L]

jdMorgan




msg:4131786
 3:30 am on May 13, 2010 (gmt 0)

> ... please specify the current URL, the new URL, and the actual server filepath -- all three are needed to make sense of this kind of function.

Also, please describe the desired function of the three exclusions.

Jim

ivanvias




msg:4131789
 3:38 am on May 13, 2010 (gmt 0)

Hmm, Basically my pages work when they are in this format http://www.example.com/com/mem/sitename

What i want is whenever i link http://www.example.com/sitename it shows the same page as above except with this new url.


the 3 exclusions are just so those files or pages dont cause 404

jdMorgan




msg:4131797
 4:05 am on May 13, 2010 (gmt 0)

If you need assistance, please make an effort to answer the questions posted here to get the information necessary to solve your problem, and to answer those questions exactly as posed.

What is the old URL? http://www.example.com/com/mem/sitename
What is the new URL? http://www.example.com/sitename
What is the actual server filepath to user files? ___________

If you remove "/mem" from your URLs, then your site cannot have any subdirectories added to it, because there will be no way to tell if a request is for a 'support' subdirectory or for a 'user.'

For example a request for http://www.example.com/w3c/p3p.xml could be a request for your standard-location w3c-specified privacy policy, or it could be a request for the 'p3p.xml' file in the filespace of your user "w3c". There is no way to resolve this problem, short of listing each and every subdirectory in both .htaccess and your "sign up as a user" script, and preventing anyone from signing up with that username.

By putting the usernames in the top-level directory-path, you effectively allow users to control what you can and cannot name your subdirectories in the future. That's a bad plan. Consider using user-subdomains instead, if your server has (or can have) a unique IP address. Otherwise, I strongly recommend that you keep the "/mem" path in the URL. Or shorten it to just "m" if you like, but leave something in the URL that distinguishes 'user' requests from requests for 'real' subdirectories.

Note that on large sites where many, many subdirectory-paths can be created, it is common to split them up by intial letter or letters in order to avoid serious performance problems that occur when a directory contains too many files or subdirectories. Thus user Adam's URLs all start with /a/adam/ and user Bill's URLs all start with /b/bill. In this case, the code can easily key off "single-letter" subdirectory name to tell whether a request is for a user subdirectory or a 'real' subdirectory. Just another option here, if you're planning for success...

Why I asked for three different paths above:
  • You need to redirect the old URL to the new URL.
  • You may need to rewrite requests for the new URL to the correct (old) internal filepath.
  • You may wish to redirect direct client requests for the internal filepath back to the new URL.

    Only by knowing all three paths is it possible to determine the proper solution.

    Jim

  • ivanvias




    msg:4132053
     3:48 pm on May 13, 2010 (gmt 0)

    okay, Initially i wanted to have user subdomains. is there a way to acknowledge

    http://sitename.example.com to

    http://www.example.com/com/mem/sitename

    [edited by: jdMorgan at 4:36 pm (utc) on May 13, 2010]
    [edit reason] De-linked [/edit]

    g1smd




    msg:4132079
     4:16 pm on May 13, 2010 (gmt 0)

    Yes, for that you would use a rewrite, not a redirect.

    In this case you're associating the URL sitename.example.com with the internal server filepath /com/mem/sitename.

    URLs don't exist inside a server. They exist only out on the web.

    ivanvias




    msg:4132251
     9:16 pm on May 13, 2010 (gmt 0)

    What it comes down to is this.

    Old url : http://www.example.com/com/mem/site?sn=sitename

    New Urls : [sitename.example.com...]


    and [sitename.example.com...]

    ivanvias




    msg:4132255
     9:33 pm on May 13, 2010 (gmt 0)

    I found something a bit similar here :

    # Internally rewrite <subdomain>.example.com/<URLpath> to example.com/subs/<subdomain/<URLpath>
    RewriteCond $1 !^subs/
    RewriteCond %{HTTP_HOST} !^www\.example\.com
    RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
    RewriteRule (.*) /subs/%1/$1 [L]

    ivanvias




    msg:4132270
     10:17 pm on May 13, 2010 (gmt 0)

    I am not sure why this isnt working for my site

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com
    RewriteRule ^/(.*)$ /com/mem/site?sn=%1 [L]

    [edited by: tedster at 12:59 am (utc) on May 14, 2010]
    [edit reason] switch to example.com [/edit]

    jdMorgan




    msg:4132356
     2:15 am on May 14, 2010 (gmt 0)

    Because you left out the first RewriteCond from the example you found, which prevents the rule from looping "infinitely."

    To stop that on your site, you'll need to exclude /com/mem/ or just /mem/ -- I can't tell because you never answered by third question above.

    Your code will also lose the "page" requested by the user -- bill.example.com/ and bill.example.com/page may end up being the same 'page' -- probably not what you want.

    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