RewriteRule for multiple folders

I use this code below:

RewriteRule ^([a-zA-Z0-9\_\.\-\+]+)\+\=([a-zA-Z0-9\=\+]+).html$ /myfolder-A/

This code work perfectly. I need to change it to allow access to others folders:

/myfolder-ABC/
/myfolder-ygh/
/myfolder-OP1/

Etc. without creating them on server.

wassim,

First, it looks like you’ve used overkill escaping every non-alphanumeric character you have in your regex.

[quote=http://www.ietf.org/rfc/rfc2396.txt Uniform Resource Identifiers (URI): Generic Syntax]2.2. Reserved Characters

Many URI include components consisting of or delimited by, certain
special characters. These characters are called “reserved”, since
their usage within the URI component is limited to their reserved
purpose. If the data for a URI component would conflict with the
reserved purpose, then the conflicting data must be escaped before
forming the URI.

  reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                "$" | ","

The “reserved” syntax class above refers to those characters that are
allowed within a URI, but which may not be allowed within a
particular component of the generic URI syntax; they are used as
delimiters of the components described in Section 3.[/quote]

On with your question: How do you plan to differentiate which URIs are redirected to A, ABC, ygh and OP1? You cannot make multiple redirections without some sort of marker to let Apache know what to do - the Apache daemon is not clairvoyant!

You might benefit from reading the mod_rewrite tutorial at http://dk.co.nz/seo as it contains explanations and sample code. It’s helped many SitePoint members over the years and should help you, tYou might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

Regards,

DK

hi Aiptek

thanks for the explanation, it help, i know that the apache deamon is not clairvoyant. :smiley: may be my question was’nt clear. so : my goal is to make an automatic naming for the folder to improve my website SEO, it’s not about:

/myfolder-ABC/
/myfolder-ygh/
/myfolder-OP1/

i dont want to create them manually, its about one hundred folders or more thanks.

wassim,

Okay, I’m not clairvoyant either! :wink: Of course, late at night, my brain may not be functioning sufficiently to understand the problem. :sleepy:

Because mod_rewrite isn’t written for creating new directories, please let me recommend doing that with a PHP script because:

  1. PHP can test to determine whether the directory exists
  2. PHP can create a new directory (and assign read/write/execute permissions)
  3. PHP is a very good language to use to create a decision tree.

IF ABC, ygh and OP1 are your clients (or users), they KNOW their “username” (directory) and should be made to enter their directory with the correct URI (with an error handler to catch errors in URIs).

Sorry, still an incomplete explanation but the mod_rewrite tutorial should give you a place to start if you’re intent on using that for (???) but you’ll have an easier time creating directories with PHP.

Regards,

DK

dklyn instead of Aiptek, sorry for username, I didn’t drank my coffee yet :dizzy_face:
i think i will I’ll change my mind about naming folders, and try other solution, i’ll post it later once done.
thanks a lot.

wassim,

No worries, mate! Good Luck with your project!

Regards,

DK

hello,

my first goal is to improve my SEO, so i did it without folders, i mean i append the folder name at begin of url simply :chart_with_upwards_trend:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.