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
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
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
> ... 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
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
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
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
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
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
[edited by: tedster at 12:59 am (utc) on May 14, 2010] [edit reason] switch to example.com [/edit]
jdMorgan
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.