Forum Moderators: phranque

Message Too Old, No Replies

Show contents of a folder as if it's coming from a different url

         

ambaxter

5:51 pm on Apr 25, 2011 (gmt 0)

10+ Year Member



Not sure if this is possible without creating a symlink, but is it possible to pull up a URL (and subsequent files) from /server/folder/ and have it behave is if they were coming from /custom/url/ with HTACCESS?

g1smd

6:27 pm on Apr 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, it is called an "internal rewrite".

RewriteRule ^custom/url/(.*)$ /server/folder/index.htm?param=$1 [L]


However, do not use "index.htm" in the URL out there on the web.

Link to the URL that you want your users to see and use. URLs are defined in links.

ambaxter

2:01 am on Apr 26, 2011 (gmt 0)

10+ Year Member



man, so simple! Thanks for this very simple and helpful response.

g1smd

9:07 am on Apr 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Depending on EXACTLY what you want to do, the code can vary:

RewriteRule ^custom/url/(.*)$ /server/folder/$1 [L]

ambaxter

12:51 pm on Apr 26, 2011 (gmt 0)

10+ Year Member



Yes, the second approach is what I used. Thanks again. I was trying various versions of rewrites and nothing was working.

g1smd

10:57 pm on Apr 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nailing the exact requirements is crucial when you're dealing with server configuration code.

My first post was the right answer to the wrong question. Glad you fixed it.

ambaxter

7:35 am on Apr 27, 2011 (gmt 0)

10+ Year Member



Good morning,

I've got this all working properly, but I am curious if there's a way "clean up" the rewrites I've got going.

I have the following:
RewriteRule ^custom/url/images(.*)$ /server/folder/images$1 [L]
RewriteRule ^custom/url/css(.*)$ /server/folder/css$1 [L]
RewriteRule ^custom/url/assets(.*)$ /server/folder/assets$1 [L]

It works as I would have expected. I'm ONLY rewriting selected folders in a given directory.

I'm satisfied with it, but it seems like there should be a way to do it in a single statement.

Here's what I attempted:

RewriteCond $1 ^custom/url/css
RewriteCond $1 ^custom/url/images
RewriteCond $1 ^custom/url/assets
RewriteRule (.*) /server/folder/$1 [NC,L]

g1smd

8:35 am on Apr 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The URL request
example.com/custom/url/css/something
will rewrite to the internal path at
/server/folder/custom/url/css/something
.

You need this code:
RewriteRule ^custom/url/(css|images|assets)/(.*)$ /server/folder/$1/$2 [L] 

ambaxter

8:40 am on Apr 27, 2011 (gmt 0)

10+ Year Member



Cool man, thanks again for your awesome help! I'll give this a go.

Update: Works perfectly. Now I know how to do it for future reference.

g1smd

9:42 am on Apr 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This other thread, especially the "six concepts" post might be useful too: [webmasterworld.com...]