Mod_rewrite?

Got Problems or Advice post here. Want to show off your PC bling?
PC, Xbox 360, PS3, Wii, Electronics.
Post Reply
User avatar
madmattd
Admin
Posts: 780
Joined: October 9th, 2009, 7:00 pm
Ingame Name: [ATG] madmattd
SteamID: STEAM_0:0:22659932
Location: MA

Mod_rewrite?

Post by madmattd »

I was wondering if anyone here has worked with mod_rewrite commands. I am trying to write some rewrite rules for a CMS I am using, and let's just say I have no clue about mod_rewrite, and it seems like 30% of the questions asked on the CMS's forums (about anything, not just mod_rewrite, those are near a 90% fail I swear) just never get answered. How nice. Anyway, if anyone can help me out, it shouldn't take more than a few minutes for someone that knows what they are doing. Let me know, thanks!
"Chinese Sentries - they're cheap, crappy, and have little lights on the top!" - Pretendica
User avatar
Joe
Founder
Posts: 574
Joined: June 14th, 2009, 12:58 am
Ingame Name: [ATG] Joe
SteamID: STEAM_0:0:3883133
Location: Toronto, Ontario
Contact:

Re: Mod_rewrite?

Post by Joe »

I know a bit about mod_rewrite, so I can try and help, you might also want to check out http://www.modrewrite.com/ if you haven't already.
This is a block of text that can be added to posts you make. There is a 500 character limit.
User avatar
madmattd
Admin
Posts: 780
Joined: October 9th, 2009, 7:00 pm
Ingame Name: [ATG] madmattd
SteamID: STEAM_0:0:22659932
Location: MA

Re: Mod_rewrite?

Post by madmattd »

Thanks a bunch Joe, I figured someone here had at least used it. I've certainly read some things on mod-rewrite, but couldn't figure out what I needed. I'm sure it was there, but anyway. I'll spell out the deal real quickly here and we can discuss here or in Steam, it doesn't matter much to me.

As I mentioned I am using a CMS in this particular case. Obviously I would like friendly URLs instead of index.html?a=15 and so on for each page. So I've enabled the writing of the friendly urls so you get something like [site_root]/hi/yo. No problems here, they supplied an .htaccess file with the friendly urls rewrite rules:

Code: Select all

# Vital components of your .htaccess file
RewriteEngine On
RewriteBase /

# The Friendly URLs part

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
This works fine. /pagename15 is rewritten to /index.php?q=15 (actually I think it is /index.php?q=pagename15)for parsing by the server. However, I've added a blogging script to the page, which has tagging capabilities that I'd really like to use. With friendly urls turned on, these links are printed to the browser along the lines of /blog/?tag=news&key=tags, where news is the tag in this case of course. These links return 404 errors. I enabled logging briefly in the rewrite module and found that this link was being rewritten to:

Code: Select all

Sun Jan 30 11:28:40 -  3256 - DoRewrites: Rewrite Url to: '/index.php?q=index.php?q=blog.html?tag=news&key=tags&tag=news&key=tags&q=blog.html?tag=news&key=tags&tag=news&key=tags'
Obviously not right. I need it to rewrite to /index.php?q=18&tag=news&key=tags (well, I'm not sure of the number, but it shouldn't matter, and actually Q=blog will work too IIRC, this appears to be how the current rule works). This is the link without friendly urls on, and it works perfectly. Just not pretty. There are also some pagination parts of the site where you get something like /blog/?page=1 which is also getting rewritten wrong (404 error).

Honestly I have no issues with the query string for the tagging or the pagination, but I obviously want the friendly page names. So do I need to add something to my rewrite file to get query strings to pass through properly? Or is this a quirk of IIRF, which is handling my rewrites (IIS 6 server)? It is supposed to be 100% compatible with mod_rewrite commands and obviously it works to a point, I don't know about the query string though. The extra looping seems wrong and I suspect it is something in the rewrite rules, but nothing I've tried has fixed it and I just don't know enough to get it working. And unfortunately the forums for the CMS have given me hundreds of views, not a single reply. I could try the not heavily-trafficked IIRF forums, but if this is a simple mod_rewrite command missing as I suspect, then perhaps someone can help?

Thanks!
"Chinese Sentries - they're cheap, crappy, and have little lights on the top!" - Pretendica
User avatar
Joe
Founder
Posts: 574
Joined: June 14th, 2009, 12:58 am
Ingame Name: [ATG] Joe
SteamID: STEAM_0:0:3883133
Location: Toronto, Ontario
Contact:

Re: Mod_rewrite?

Post by Joe »

Try this maybe

Code: Select all

RewriteRule ^(^?*)?(^?.*)$ index.php?q=$1&$2 [L,QSA]
This is a block of text that can be added to posts you make. There is a 500 character limit.
User avatar
madmattd
Admin
Posts: 780
Joined: October 9th, 2009, 7:00 pm
Ingame Name: [ATG] madmattd
SteamID: STEAM_0:0:22659932
Location: MA

Re: Mod_rewrite?

Post by madmattd »

All pages are now 404. Except home page of course. Hmm.
"Chinese Sentries - they're cheap, crappy, and have little lights on the top!" - Pretendica
User avatar
madmattd
Admin
Posts: 780
Joined: October 9th, 2009, 7:00 pm
Ingame Name: [ATG] madmattd
SteamID: STEAM_0:0:22659932
Location: MA

Re: Mod_rewrite?

Post by madmattd »

Looking at a new rewrite engine, me thinks IIRF is fail. Thanks for the chat help though Joe.
"Chinese Sentries - they're cheap, crappy, and have little lights on the top!" - Pretendica
User avatar
Mullet
Donor
Posts: 384
Joined: October 14th, 2009, 5:16 pm

Re: Mod_rewrite?

Post by Mullet »

Reading that make my head hurt.
User avatar
madmattd
Admin
Posts: 780
Joined: October 9th, 2009, 7:00 pm
Ingame Name: [ATG] madmattd
SteamID: STEAM_0:0:22659932
Location: MA

Re: Mod_rewrite?

Post by madmattd »

Mullet wrote:Reading that make my head hurt.
You should've seen the Steam chat... :o
"Chinese Sentries - they're cheap, crappy, and have little lights on the top!" - Pretendica
User avatar
madmattd
Admin
Posts: 780
Joined: October 9th, 2009, 7:00 pm
Ingame Name: [ATG] madmattd
SteamID: STEAM_0:0:22659932
Location: MA

Re: Mod_rewrite?

Post by madmattd »

It turns out the original rule ought to work. I've checked a rewrite tester and the original rule from the .htaccess file is supposed to append the query string correctly. IIRF apparently fails, even though it allegedly supports QSA. Time to tell the author his code fails...
"Chinese Sentries - they're cheap, crappy, and have little lights on the top!" - Pretendica
Post Reply