Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite - advanced help :)

Drupal Path Module

         

RDWest2005

3:08 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



Hello guys,
I'm new here so I hate to dive in with a hard one. (at least it is to me)

For the life of me, I can not figure out how drupal cms uses the path module. I'm trying to write a custom classified ads script and my client has a PR of 4. So, i need to be able to use the same rules as drupal cms does...

In .htaccess...

[b]

<IfModule mod_rewrite.c>
RewriteEngine on

# Rewrite current-style URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
[/b]

Creating a URL Alias is beyond me, this is my first time ever with rewrite :(

In mysql there is
src = /node/2345 or /taxonomy/term/3
dst = index.html etc...

i see the rule in htaccess and see what is in mysql...
but I can't seem to understand this at all...

my app will be mysql driven with smarty template engine

I can't seem to make links.php?page=1245 rewrite to home.htm

Can someone shoot me in the head with the answer?

:)

Thanks much,
Forgive me English - It's bad
~RD

[edited by: RDWest2005 at 3:11 pm (utc) on Aug. 9, 2007]

RDWest2005

4:31 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



This is what I can't figure out...

I don't see how the src url eg page.php?q=x and from mysql by a src and dst url...

I don't see how it is passed into the rewrite!-f and!-d

Can anyone explain this?

Thanks,
~R

jdMorgan

5:11 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't understand your questions, but let's get on solid ground here.

The "-f" and "-d" RewriteConds are checking for file exists and directory exists. "!" is a logical NOT operator.

So the effect of your code is rewrite any requested URL-path to index.php unless it exists as a physical file or directory. For example, if a robot requests your robots.txt file, and that file exists, then the request will not be rewritten to your index.php script.

I presume that you now need to exclude some additional specific virtual URL-paths from being rewritten to index.php, and wish to rewrite them to your ads script instead. So, to get organized, you will need to define three classes of URLs: Those to be rewritten to index.php, those to be rewritten to you ads script, and those that should not be rewritten at all. Your existing code can serve as an example of the first and third classes, but you'll need to thoroughly define the second class. This only sounds complicated because I'm using generalized language here, due to the fact that I do not know what all of your URLs look like.

Jim

RDWest2005

5:50 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



I've been at this untill I'm pulling my hair out - Sorry...
Mainly I need to rewrite dynamic links as an alias to ./filename.htm

more than likely my links will all be in the form of index.php?page=1234 from the way i code my pagination.

The only other links will be maybe a GET with search or submit GO action like so dev01/links.php?page=1000&Submit=Go

I've not yet included search so I can't post exactly the link i'll come up with.

I was looking through drupal since i've used it in my personal site.

The PATH module is doing a alias from mysql with 3 fields (id,src,dst) so no matter what the original src link is lets say -- domain.com/node/17

now defining an alias in mysql becomes

src = node/17
dst = mypage.htm

and it rewrites whatever term to your alias...

So even if i have to do this a per page basis, that would even be fine...

the main thing is i can't rename his main catagories buz.htm free.htm etc to something like
index.php?page=15 etc because he will loose his PR4

thanks much,
I'm dieing here :(

:)
~R

EDIT, believe it or not, i've run my own servers and provided hosting services for almost 10 years and have never really had to use mod_rewrite except for non-www to www etc - simple rules and i go on about my business :)

[edited by: RDWest2005 at 5:52 pm (utc) on Aug. 9, 2007]

RDWest2005

6:39 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



I can't seem to even get a per page working ..

with htaccess in same dir as index page

index.php?page=12

i need it to create the url as

mypage.htm

i'm not any good with regx - sorry

~R

[edited by: RDWest2005 at 6:39 pm (utc) on Aug. 9, 2007]

jdMorgan

6:45 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's very difficult in a forum venue to 'get our arms around' everything that you're doing. And I'm off to a meeting here. But I want to interject a couple of points here. First, you will have to solve this problem -- We can only help. But we can't see over you shoulder.

Second, that term you are using: "links." Links on the page determine the URL -- The URL that search engines will follow and the URL that they will list in search results. So, no amount of mod_rewrite internal rewrites can "change" that URL from dynamic to static (search-engine friendly). If you need to do that, then either use preg_replace in the script that produces the page to make the URL static-looking, or change the URL in the database (possibly adding a new entry to each record in the db.

*After* your friendly/static URL is requested, then mod_rewrite can parse it and rewrite it into the dynamic form needed to invoke your script. But mod_rewrite is not an "output filter" for the content of your pages, it is an "input filter" for URLs being requested from your server; Mod_rewrite is invoked after a request arrives from a client, and before any content-handlers or scripts are invoked. It modifies only incoming URLs, so that you can change the filepath that will be used to server content for that URL.

Check out the Apache forum section of the WebmasterWorld library [webmasterworld.com] for more info.

Jim

RDWest2005

6:54 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



blahh, i think i'm figuring it out now.
I see what your saying.
I need a seo friendly url.
the .htm don't exist.
so my script needs to write the link as /page.htm
then mod rewrite replaces that page with links.php?page=111

and it is sent to my script and i grap with GET

i'm seeing a lil light, but i'm still not seeing how i'll do this

~R

RDWest2005

7:05 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



GOT IT!

omg, i was making something so simple into something that didn't exist

i got it with making my link as page.htm
then replacing page.htm with links.php?page=1

thanks, you made me understand how it was working...
~R

phranque

7:18 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, RDWest2005!

and your english is fine...

jdMorgan

2:50 am on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> and your english is fine...

I'd say *great* actually. Conversational English is one thing, but trying to communicate clearly about technical matters is far more difficult!

I'm glad we could help.
Jim

RDWest2005

5:04 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



Thanks,
I've got this to working and I understand how it works.

I'll tell you what I can't figure out yet.

The seo friendly link is written to the html output to page
eg: <a href=whatever.htm

Now within the drupal PATH module, the whatever.htm is stored as an alias in mysql uder a field (src) the the real link .php?q=x is stored as (dst) destination i assume...

I can't figure out how the regx is taken from mysql with dst and then passed to mod_rewrite with the htaccess I posted at beginning of this thread.

~R

jdMorgan

10:01 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It probably isn't passed to mod_rewrite, since that would require an external redirect and a second HTTP transaction (browser request) which would be very inefficient.

Rather, all requests for non-existent file and directory URL-paths are rewritten by mod_rewrite to invoke the script, with the requested URL-path passed as the "q=" parameter. Based of the requested URL in the "q=" parameter, the script looks up the necessary *files* and variables from the database, and using those variables, it opens, modifies, and/or #includes those files and variables to build the requested "page."

Jim

RDWest2005

12:53 am on Aug 11, 2007 (gmt 0)

10+ Year Member



Thanks for the explanation.
I've went all through the modules code and its only to manipulate the info in mysql from all i can tell...

I'll just create each rule in htaccess for now...

Thanks for the help,
~R