Forum Moderators: phranque

Message Too Old, No Replies

rewrite rule for virtual folder in url htacesss

         

vn412

12:57 pm on Dec 29, 2011 (gmt 0)

10+ Year Member



I have created a simple dynamic website with php and I am having trouble making my URL structure.
I want my url to be
[mydomain.com...]
should go to
classifieds folder index page but the url should be like above.
i have written the rewrite rule in htaccess but its not working:
the folder abc above in example can be dynamic any combination of letters from a-z

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule ^(.+)\.com\/([a-z]+)\/classifieds\/ [mydomain.com...] [NC]

please help me out.
Thanks in advance

phranque

2:53 pm on Dec 29, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, vn412!

i've highlighted some key phrases below from the apache mod_rewrite documentation (but you should read the whole referenced note)...

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule:
Note: Pattern matching in per-directory context
...
If a substitution string starts with ``http://'', ... an external redirect ... is forced!


you want to do an internal rewrite rather than an external redirect, so remove the scheme and hostname (and parent directory) from the substitution string.

g1smd

3:21 pm on Dec 29, 2011 (gmt 0)

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



Rule pattern can match only the requested path, not the domain name. Remove the domain name parts of the pattern.

Slashes do not need escaping.

Add the [L] flag to every rule.

With a domain name in the target you force a 302 redirect. The target should be only an internal path.

This question is asked almost every day here so there are thousands of previous threads with example code. Indeed you're the third person today to ask about this.

vn412

7:37 am on Dec 30, 2011 (gmt 0)

10+ Year Member



I m newbie, Could you pls help me with the syntax how can do this to get the result, as I wrote i tried abover code but gives me error "folder abc does not exist"

lucy24

4:52 pm on Dec 30, 2011 (gmt 0)

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



Well, does it exist? If it doesn't, you will need to follow-up your redirect with a rewrite telling the server where to find the information.

Uhm, don't you have a parallel thread asking the identical question? It seems awfully familiar, though that may be because the redirect-plus-rewrite two-step is the Hot Question of the Hour.