TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-14-2008, 02:25 AM   #1 (permalink)
The Wanderer
 
Join Date: Sep 2007
Posts: 12
Thanks: 0
trs21219 is on a distinguished road
Help Mixed Mod_Rewrite with non

ok this is my problem. i hate having to make a new mod rewrite rule everytime i want to add a variable in the url of my websites. i like the way mod rewrite works as it simplify's my visitors browsing and it makes it easier for search engines to find me...

this is what i want. i need a way for my for my pages to use mod rewrite for my components and sub components (act and sub) but then for things like page or article i want to be able to add the old freind ?article= at the end and not have any issues. if you dont get what i mean ill show you below.

Code:
i want this:
www.mysite.com/index.php?act=news&sub=recent&page=2&show=25
to be made into this:
www.mysite.com/news/recent.html?page=2&show=25
using mod rewrite for the act and the sub (or whatever else i put into the mod rewrite page) but still have the ability to just add variables into the url and have them work.
PLEASE HELP!!!
trs21219 is offline  
Reply With Quote
Old 01-14-2008, 10:47 AM   #2 (permalink)
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
sjaq is on a distinguished road
Default

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]

RewriteRule ^([a-z0-9]+)/([a-z0-9]+).html index.php?act=$1&sub=$2 [QSA,L,NC]
for explanation: mod_rewrite cheat-sheet [PDF]

Last edited by sjaq : 01-14-2008 at 06:49 PM. Reason: cheat-sheet added
sjaq is offline  
Reply With Quote
The Following User Says Thank You to sjaq For This Useful Post:
Alan @ CIT (01-15-2008)
Old 01-14-2008, 06:09 PM   #3 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 20
Thanks: 1
iisbum is on a distinguished road
Default

I think what you want to do is something like this (one of the rewrite rules from sites):

Quote:
RewriteRule ^([0-9A-Za-z]+)/([0-9A-Za-z]+)/?$ /engine/index.php?section=$1&action=$2&%{QUERY_STRING} [L]
The relevant bit is the %{QUERY_STRING} bit which will pass any variables on the URL into your script.

Mubs
iisbum is offline  
Reply With Quote
Old 01-14-2008, 06:29 PM   #4 (permalink)
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
sjaq is on a distinguished road
Default

The [QSA] part at the end of my rule does exactly the same only cleaner...
sjaq is offline  
Reply With Quote
Old 01-15-2008, 08:02 AM   #5 (permalink)
The Wanderer
 
Join Date: Sep 2007
Posts: 12
Thanks: 0
trs21219 is on a distinguished road
Smile

thank you both very much. i will make sure to try those and hopefully that will save me alot of hassle
trs21219 is offline  
Reply With Quote
Old 01-15-2008, 02:15 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Just a technical note, the QSA flag appends any query string to the end of the rewritten request in the same way that Mubs' code does. However, a little tweak in the placement of the %{QUERY_STRNG} variable might be of use (or just a fanciful idea).

Consider the following url after rewriting: index.php?section=news&action=recent&<QS> (<QS> is just a placeholder to save space). If the requested url was: /news/recent.html?section=auctions then that request would be rewritten to: index.php?section=news&action=recent&section=aucti ons (sorry vbulletin inserts a space unnecessarily) which would call the recent action within the auctions section, not news!

The tweak to Mubs' rule would be to move the placement of the query string variable:
index.php?%{QUERY_STRING}&section=$1&action=$2

This means that even if section and/or action are passed through the query string manually, the "path" versions will always be used. All that said, it's a minor point and you may choose to simply use the QSA flag and accept the 'false' values in the query string.
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:19 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design