homepage Welcome to WebmasterWorld Guest from 54.211.157.103
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod_rewrite static URL to dyn. Url w/3 vars.
bobp1




msg:1509235
 3:47 pm on Aug 5, 2003 (gmt 0)

Hi:

Been reading everything I can find for several days.
Beginners guide, Tutorials, and dozens of the posts here, but still haven't got it right...

Trying to change:
This ==>http://mysite.com/Dir1/Dir2/Dir3/Var1/Var2/Var3

To This ==>http://mysite.com/Dir1/Dir2/Dir3/Var1.php?c=Var2&p=Var3

1)Mod_rewrite functional(tested with a page substitution)
2)No httpd.conf access ..so using .htaccess file in root
3)All Vars will be 'alpha'
4)Getting Not Found error using the following:

Options +FollowSymlinks
RewriteRule ^(.*)/Dir1/Dir2/Dir3/(.*)/(.*)/(.*)$ $1/Dir1/Dir2/Dir3/$2\.php?c=$3&p=$4 [L]

Thanks for any help, advice and/or direction.

Bob

 

Storyteller




msg:1509236
 8:22 pm on Aug 5, 2003 (gmt 0)

For all mod_rewrite problems, enable logging and set its level to 9 first thing:

RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

In 9 cases of 10, what's wrong can be seen from the log. If not, post an excerpt here - we'll try to help.

jdMorgan




msg:1509237
 8:35 pm on Aug 5, 2003 (gmt 0)

bobp1,

Welcome to WebmasterWorld [webmasterworld.com]!

This ==>http://mysite.com/Dir1/Dir2/Dir3/Var1/Var2/Var3

To This ==>http://mysite.com/Dir1/Dir2/Dir3/Var1.php?c=Var2&p=Var3

Options +FollowSymlinks
RewriteRule ^(.*)/Dir1/Dir2/Dir3/(.*)/(.*)/(.*)$ $1/Dir1/Dir2/Dir3/$2\.php?c=$3&p=$4 [L]


First, You don't need $1 or the corresponding ^(.*) in your RewriteRule - The domain name is not part of the URL seen by RewriteRule.
So now we have:

RewriteRule ^Dir1/Dir2/Dir3/(.*)/(.*)/(.*)$ /Dir1/Dir2/Dir3/$1\.php?c=$2&p=$3 [L]

Second, "(.*)" is going to accept any number of any characters, including blank, as a match. I'd suggest "(.+)"
Third, do not escape literals except in patterns; "\." should not be used in the substitution string!
So that makes it:

RewriteRule ^Dir1/Dir2/Dir3/(.+)/(.+)/(.+)$ /Dir1/Dir2/Dir3/$1.php?c=$2&p=$3 [L]

Finally, you need a RewriteEngine on directive in there, too - in case it's missing:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^Dir1/Dir2/Dir3/(.+)/(.+)/(.+) /Dir1/Dir2/Dir3/$1.php?c=$2&p=$3 [L]

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

bobp1




msg:1509238
 12:50 am on Aug 6, 2003 (gmt 0)

Wow, that's just like trying 'Open Sesame' on a blank cliff
face and having it work!

My thanks to Storyteller and jdMorgan for the help and clarifying instructions.......

Now getting correct page/s, but lost all my images and the style sheets......

Seems to be looking for them in the next directory below the called page (unfortunetly they're in directories on the same level as the called page).....

Tried an exclusion just before the RewriteRule as follows:

RewriteCond %{REQUEST_URI}!\.(cssjsjpe?ggifswf)$

No go....same result...get the page with no styling/images.

Realize I can move the stylesheets and images....but
is there possibly another avenue to expore?

Thanks again.

Bob

jdMorgan




msg:1509239
 1:41 am on Aug 6, 2003 (gmt 0)

bobp1,

Take a look at your error log and find out where the server is looking for these missing image/js/css files both with and without the exclusion Cond; adding that exclusion should have changed things if the image/js/css requests were matching (and invoking) the RewriteRule.

With that knowledge, you should be able to compose a rule to rewrite the image/js/css URLs before testing/rewriting the script calls. Terminate the image/js/css rewrites with an [L] flag so the URL does not get rewritten twice.

RewriteCond %{REQUEST_URI} \.(cssjsjpe?ggifswf)$
RewriteRule <some pattern and substitution for images/js/css> [L]
RewriteRule ^(.*)/Dir1/Dir2/Dir3/(.*)/(.*)/(.*)$ $1/Dir1/Dir2/Dir3/$2\.php?c=$3&p=$4 [L]

If you're still having trouble, please post a before & after (actual & rewritten) URL for an image file as an example - I can't work out how you are calling images and how they might fit into (match) your existing RewriteRule. (Change the domain name to comply with WebmasterWorld TOS)

Jim

bobp1




msg:1509240
 12:35 pm on Aug 6, 2003 (gmt 0)

I couldn't invoke the rewritelog from the .htaccess file...
kept shutting me down with a '500'. So got the following
info from the access log.

The info in the access log did not change whether the - RewriteCond %{REQUEST_URI}!\.(cssjsjpe?ggifswf)$
was included or not....the access log showed server looking
in same place.

Server is trying to access images at:

[mysite.com...]

They are actually located at:

[mysite.com...]

I tried the following:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^Dir1/Dir2/Dir3/(.+)/images/(.+)\.(cssjsjpe?ggifswf)$ /Dir1/Dir2/images/$2.(cssjsjpe?ggifswf) [L]

RewriteRule ^Dir1/Dir2/Dir3/(.+)/(.+)/(.+)$ /Dir1/Dir2/Dir3/$1.php?c=$2&p=$3 [L]

Get the page but not the images.

Thanks again for any further direction.

Bob

jdMorgan




msg:1509241
 1:29 pm on Aug 6, 2003 (gmt 0)

bobp1,

You can only use an alternation in a pattern, not in a substitution, so try this:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^Dir1/Dir2/Dir3/(.+)/images/(.+)\.(cssjsjpe?ggifswf)$ /Dir1/Dir2/images/$2.$3 [L]
RewriteRule ^Dir1/Dir2/Dir3/(.+)/(.+)/(.+)$ /Dir1/Dir2/Dir3/$1.php?c=$2&p=$3 [L]

Jim

bobp1




msg:1509242
 12:39 am on Aug 7, 2003 (gmt 0)

That gets me my images....

Many Thanks,

Bob

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved