Forum Moderators: phranque

Message Too Old, No Replies

rewrite working but not as expected

rewrites a url that i don't expect to to include

         

alternapop

10:18 pm on Mar 15, 2010 (gmt 0)

10+ Year Member




I'm trying to do a url rewrite to hide /index.php/. I've done this successfully for 2 other sites, with help from here previously, but this one is behaving differently.

the data resides here: /volumes/data/cls/
inside of this folder is a php web content (expression engine) installation

#cls
RewriteCond %{HTTP_HOST} ^(.*)testserver\.university\.edu$ [NC]
RewriteRule ^/cls(.*)$ /cls/index.php/cls$1 [L]


the rewrite and the hiding of /index.php/ works but the issue is that we can't get the Expression Engine control panel page to load. it just acts like it's loading "testserver.university.edu/cls" instead of the control panel page.

nowhere in the rewrite code or in the url we load contains the control panel url so i don't understand why it's not working.

[testserver.university.edu...] (example control panel url)
... rewrites to...
[testserver.university.edu...]

... in appearance, but the url stays the same as what's typed. because we're loading a url that contains "clsee_system", i don't understand why it's rewriting.

what is working... (an example)

[testserver.university.edu...]
...rewrites to...
[testserver.university.edu...]

i don't want this url to rewrite:
[testserver.university.edu...]

any ideas?

thanks!

g1smd

12:24 am on Mar 16, 2010 (gmt 0)

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



The cls(.*) pattern matches anything that begins with 'cls' and so matches 'clsee' too.

alternapop

3:02 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



i was wondering if that might be the cause... how do i work around this issue here?

many thanks!

jdMorgan

3:39 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is pretty unclear. It would help to see a concise-but-thorough representative list of URLs that you *do* want to rewrite, and a list of representative list of URLs that you *do not* want to rewrite.

You may wish to rewrite *only* "/cls/index.php", or you may want to rewrite *anything but* "/cls/clsee_system/index.php", but that is not explicitly clear from what's posted. Your requirements must be exact, or any proposed code fix is not likely to work.

Also, the "rewriting" of index URL-paths to index filepaths is generally accomplished by using the Apache mod_dir DirectoryIndex directive, rather than mod_rewrite. You might want to explore that option before continuing down this mod_rewrite path.

Jim

alternapop

3:57 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



examples of what i do want to rewrite:

http://testserver.university.edu/cls/index.php/cls/services/get_around_here/
...rewrites to...
http://testserver.university.edu/cls/services/get_around_here/

http://testserver.university.edu/cls/index.php/cls/information/locations/
...rewrites to...
http://testserver.university.edu/cls/information/locations/


do not rewrite:

http://testserver.university.edu/cls/clsee_system/index.php


what's happening that i don't want is
http://testserver.university.edu/cls/clsee_system/index.php
is loading what appears to be
http://testserver.university.edu/cls/


thanks!

[edited by: jdMorgan at 4:04 pm (utc) on Mar 16, 2010]
[edit reason] Made URLs readable [/edit]

jdMorgan

4:11 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So you apparently just need an exclusion for the /cls/clsee_system/<whatever> URL-path:

# Internally rewrite requests for URL-path /cls<whatever> to /cls/index.php/cls<whatever>,
# except for requests for URL-path /cls/clsee_system<whatever>
RewriteCond %{REQUEST_URI} !^/cls/clsee_system
RewriteCond %{HTTP_HOST} ^([^.]+\.)*testserver\.university\.edu [NC]
RewriteRule ^/cls(.*)$ /cls/index.php/cls$1 [L]

All other changes to patterns and anchoring were intentional.

Jim

alternapop

4:22 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



jim, thanks a lot! that seems to worked... in a nutshell, can you briefly explain why the exception was needed in this case? i have two others working in a similar fashion that didn't require that.

i'll read up on mod_dir right away... if you have any favorite links/books, please let me know.

jdMorgan

5:21 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The exception was needed because otherwise the RewriteRule pattern matches anything that starts with "/cls".

Mod_rewrite involves two very-powerful components: The mod_rewrite directives themselves, and Regular Expressions pattern-matching. Both are misleadingly-compact, but extremely powerful. Taken together and implemented with due attention to detail, they can implement URL-to-URL redirection, non-default URL-to-filename mapping, access controls, or reverse-proxy through-puts. Used cavalierly, they can take down your server instantly -- or worse, slowly ruin your search engine rankings and put you out of business with a single typo.

Favorite link: [apache.org...]

Further resources: Apache Forum Charter [webmasterworld.com] (see links) and Apache Forum Library [webmasterworld.com] (previous threads & tutorials)

Jim

alternapop

6:34 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



thanks!