Forum Moderators: phranque

Message Too Old, No Replies

modrewrite except to a specific directory

         

conceptcrew

4:58 pm on Oct 6, 2009 (gmt 0)

10+ Year Member



I have this rewrite installed for a script but have installed a blog script in a subdirectory that cannot be seen due to the rewrite functions from the first script.

how can i have the rewrite functions work for the main script while not affecting the one subdirectory containing the blog?

RewriteRule ^album/(.*)\.html$ albums.php?album=$1 [L,NC]
RewriteRule ^album/(.*)/([0-9]*)$ albums.php?album=$1&page=$2 [L,NC]
RewriteRule ^([a-zA-Z0-9]*)/$ lyrics.php?letter=$1 [L,NC]
RewriteRule ^([a-zA-Z0-9]*)/([0-9]*)$ lyrics.php?letter=$1&page=$2 [L,NC]
RewriteRule ^lyrics/([0-9]*)/(.*)\.html$ viewlyrics.php?id=$1&title=$2 [L,NC]
RewriteRule ^singer/(.*)\.html$ singer.php?singer=$1 [L,NC]
RewriteRule ^singer/(.*)/([0-9]*)$ singer.php?singer=$1&page=$2 [L,NC]

the directory I do not want affected by this rewrite is

musicblog

juanyjuans

5:07 pm on Oct 6, 2009 (gmt 0)

10+ Year Member



create a new .htaccess file in that subdirectory and apply new rules to it. .htaccess is directory specific

jdMorgan

5:11 pm on Oct 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or identify which of your existing rules are interfering, and add a RewriteCond to it to exclude the blog from being affected.

Alternatively, put a 'skip' rule ahead of your existing rules, to skip them all if a blog request is detected.

The most-specific solution will cause the least pain over time, so do not choose the 'easy way' over the 'right way.'

Also, once you have the major problem sorted, please post back, as your existing rules could do with some improvements...

Jim

conceptcrew

5:18 pm on Oct 6, 2009 (gmt 0)

10+ Year Member



ah, there lies the problem ....

i have no clue how to write a skip rule

the two lines that are interfering are
RewriteRule ^([a-zA-Z0-9]*)/$ lyrics.php?letter=$1 [L,NC]
RewriteRule ^([a-zA-Z0-9]*)/([0-9]*)$ lyrics.php?letter=$1&page=$2 [L,NC]

i am assuming that the coding ([a-zA-Z0-o]) is what is doing the rewrite for everything, including my subdirectory/

I just cannot figure out how to modify that to not rewrite the specific subdirectory

conceptcrew

1:39 am on Oct 7, 2009 (gmt 0)

10+ Year Member



any suggestions?

jdMorgan

1:58 am on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# Skip next two rules if request is for anything in the '/subdirectory/' path
RewriteRule ^subdirectory/ - [S=2]
RewriteRule ^([a-z0-9]+)/$ lyrics.php?letter=$1 [NC,L]
RewriteRule ^([a-z0-9]+)/([0-9]+)$ lyrics.php?letter=$1&page=$2 [NC,L]

Note that "A-Z" has been removed from the rule patterns, as it is utterly redundant when used with the [NC] flag -- meaning "No Case sensitivity." Also, the "*" quantifiers have been changed to "+" quantifiers, because the preceding subpatterns should never be 'blank'.

Jim

conceptcrew

2:44 am on Oct 7, 2009 (gmt 0)

10+ Year Member



perfection!

Thanks a lot for your help with this.

jdMorgan

2:56 am on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now, where possible, replace all instances of "(.*)\.html" with "([^.])\.html" and all instances of "(.*)/" with "([^/]+)/" for a further improvement in execution speed.

Note however, that using "[^.]+" means that the matched string must/will not contain any periods, and that "[^/]+" means that the matched string must/will not contain any slashes. So don't use this if, for example, your 'artist' name might be "R.E.M."

However, even in that case, you'd do well to replace the "*" with "+" unless you want to allow the parameter to be completely-blank.

Jim