21
fatman
Re: Apache mod_rewrite RewriteRule Success
  • 2003/12/21 5:11

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


I'm currently converting a custom product catalogue I have into XOOPS and it used Clean URL's before so I was glad to find this thread.

I didn't use mod_rewrite however, I used a method described here.

evolt.org : clean urls with php and apache

Am I to understand that using mod_rewrite physically redirects the user? I tried the following in my .htaccess and when i went to mysite.com/contact it actually redirected me to mysite.com/modules/contact

RewriteEngine on
RewriteRule 
^contact(.*)$ /modules/contact$[L]


I hope the redirection I am have is a flaw in my .htaccess file. Redirection total defeats the purpose imho.

I was able to use the method described at evolt.org with great success. I'm tempted to use it with my XOOPS install however doing so would mean I'd have to customize every template. A small sacrifice for the great url's.

I was able to create some highly useful URL's for use in the site admin side (obviously pre-xoops). Here's an sample

/admin/products/list/all
/admin/products/list/feature
/admin/products/add
/admin/prodcuts/edit/34

The down side of doing things in XOOPS the way I did them before is that makes it really hard to work in other peoples modules and let people use mine.

If anyone is currently working on this stuff PM me. I'm hoping to get something working comprable to my old method before the in-law's arrive for x-mas dinner. :)

I'll keep trying the examples here and post links if I get anything working with my product catalog in xoops.

22
fatman
Re: Apache mod_rewrite RewriteRule Success
  • 2003/12/21 6:39

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


For anyone who is interested. This is how I implemented a clean URL structure before and what I'm attempting to hack into xoops.

.htaccess file I have following

RewriteEngine On
# If they are looking for index.php we're done
RewriteRule ^(index.php.*) $[L]

# If they are looking for a file with a file extension let them get at it
RewriteRule ^(.*..+)$ $[L

# Otherwise send their request to index.php
RewriteRule ^(.*)$ index.php?query=$[L]


Then I include the following script which basically takes whatever is stuck in the URL and sticks it in an array called $page_query

global $REQUEST_URI;
global 
$SCRIPT_NAME;

$base_href $SCRIPT_NAME;
$path explode("/",$base_href);
$template array_pop ($path);
$path implode ("/",$path);
$vars str_replace($SCRIPT_NAME""$REQUEST_URI);
$array explode("/",$vars);

$num count($array); // How many items in the array?
for ($i $i $num $i++) {
        
$page_query[$i] = $array[$i];
}


From here I have a simple configuration array which is used to define what I need to include and I provide definition for the variable passed in my query string.

$page_content[1]['name'] = 'products';
$page_content[1]['source'] = 'products/index.php';
$page_content[1]['group'] = $page_query[1];
$page_content[1]['page_func'] = $page_query[2]; 
$page_content[1]['item_id'] = $page_query[3]; 

$page_content[2]['name'] = 'news';
$page_content[2]['source'] = 'news/index.php';
$page_content[2]['group'] = $page_query[1];
$page_content[2]['category'] = $page_query[2]; 
$page_content[2]['article_id'] = $page_query[3]; 

ect..


The array method above could be customized to what ever is required and you could pass as number of variables in your query string as you want.

I really like this approach. It's proved very effective. Ultimately I ran into problems caching my templates and providing good group based access to my site, so I came searching and found xoops.

So now I have to try and hack this into the core and see if I can get it working.

If anyone thinks I'm crazy or has suggestions please let me know :)



23
sunsnapper
Re: Apache mod_rewrite RewriteRule Success

fatman,
I suspect your technique is very much in line with the Mambo technique Draven mentioned.

As for your .htaccess file doing a redirect, you are correct, it should not. Usually, a redirect occurs if you have a [R] at the end of your mod_rewrite line... not when you have a [L].

Not sure why yours would be doing that, unless it is matching a previous rule that includes a [R].

Hope that helps.

24
fatman
Re: Apache mod_rewrite RewriteRule Success
  • 2003/12/21 8:40

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


sunsnapper
I can't seem to get any of your examples to work tried on 3 servers and then added a fresh instal of XOOPS and wfsections to recreate your example exactly and still no go.

I'm not sure what other rules could be interferring there are no other lines in my .htaccess file.

I can however get my mod_rewrite example working on all the same servers and with my work-in-progress module which is excellent news.

So you don't have to look for it
RewriteEngine On
# If they are looking for index.php we're done
RewriteRule ^(index.php.*) $[L]

# If they are looking for a file with a file extension let them get at it
RewriteRule ^(.*..+)$ $[L

# Otherwise send their request to index.php
RewriteRule ^(.*)$ index.php?query=$[L]

25
sunsnapper
Re: Apache mod_rewrite RewriteRule Success

Did you change the line of code indicated in my first post?

There, it talks about a hack by Onokazu (just changing one line) that makes this work.

Here is the thread that discusses the hack:
https://xoops.org/modules/newbb/viewtopic.php?topic_id=9587&forum=7#forumpost54010

I suspect that's the issue, since many have tried the mod_rewrite code without trouble.

Hope that helps.

26
Draven
Re: Apache mod_rewrite RewriteRule Success
  • 2003/12/22 18:04

  • Draven

  • Module Developer

  • Posts: 337

  • Since: 2003/5/28


Yep, I had to do the same for mine to work.

27
fatman
Re: Apache mod_rewrite RewriteRule Success
  • 2003/12/22 23:06

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


EXCELLENT ! That did work, no I didn't notice that link in your original post. Thanks for pointing it out again. I am only sorry I didn't see it first glance, I might have saved myself a few hours this weekend.

At any rate I did come up with this combo of RewriteRule's which allow me to use the Mambo technique in my own modules without having to hack anything and making sure regular XOOPS urls still worked. But it's not as nice as your example

# if nothing is entered load document 
# that is defined as default for this dir
RewriteRule ^/() - [L]

# process any direct module links normally
RewriteRule ^(modules/*) - [L]

# If looking for an actual file or directory 
# serve it to them, else load /include.process.php
RewriteRule ^([^.]+)$ /include/process.php?q=$1 [L]

28
shivaji
Re: Apache mod_rewrite RewriteRule Success
  • 2003/12/29 1:32

  • shivaji

  • Friend of XOOPS

  • Posts: 179

  • Since: 2003/9/18


Dear sunsnapper,

I read your post many times and try to put my own .htaccesss rule for my website www.123ecominfo.com without success.

I asked my hosting providers to give me details about my server configuration. Basically I want to convert all of the links under below given Modules to friendly URLs:

1. Forum (/modules/newbb)
2. News (/modules/news/)
3. MyLinks (/modules/mylinks/)
4. Shop (/modules/shop/)
5. Contact Us (/modules/contact/)
6. Registration
7. My Downloads (/modules/mydownloads)

Is it possible for you to explain me how to define a rule for all this 7 points give above.

Thanks,


29
shivaji
Re: Apache mod_rewrite RewriteRule Success
  • 2003/12/30 15:23

  • shivaji

  • Friend of XOOPS

  • Posts: 179

  • Since: 2003/9/18


Anyone with friedly URLs conversion experince ready to help this puzzle I posted in my previous thread?

We are using Windows 2000 Server prof Edition though I hosted my site on Linux Server..I also like to know how to create and edit .htaccess file in my Windows machine ?

Thanks,

30
fatman
Re: Apache mod_rewrite RewriteRule Success
  • 2003/12/31 20:23

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


I am not certain how to accomplish friendly URL's on a windows server. But the very first examples in this thread should help you accomplish what you want if you are indeed using a linux/apache configuration.

Also look at the links in the very first post they may be of help.

Login

Who's Online

200 user(s) are online (110 user(s) are browsing Support Forums)


Members: 0


Guests: 200


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits