To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Newbies

Newbies Help for those who are just getting started

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 10-12-2009, 08:49 AM   #1
jerry_louise
Senior Member
 
Join Date: Jul 2008
Posts: 139
PHP rewrites.

Is it possible to have php set up my
HTML Code:
## PHP REWRITES ##
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_-]+)$ html/index.php?page=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ html/index.php?page=$1

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ html/index.php?page=$1&process=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ html/index.php?page=$1&process=$2
Instead of having to manually input different ones into the .htaccess file i would rather able to sent it one from my php file, perhaps making a function so i could tell it were having the "page/date/process" instead of just the "page/date".
jerry_louise is offline   Reply With Quote
Old 10-12-2009, 01:44 PM   #2
sneakyimp
Senior Member
 
Join Date: Apr 2003
Location: LA
Posts: 3,720
You should check out the RewriteMap directive. NOTE that you cannot define rewrite maps in an htaccess file -- it has to be done in the apache conf.
__________________
Write multiplayer games in AS3/PHP5 with FlashMOG 0.3.1
Find out your worth with the MyPlan Salary Calculator
sneakyimp is offline   Reply With Quote
Old 10-15-2009, 09:21 AM   #3
jerry_louise
Senior Member
 
Join Date: Jul 2008
Posts: 139
One thing i have just thought of is the possibility of using an array. This would make the .htaccess very simple and the array can be infinitely complex.

Code:
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ html/index.php?location=$1
PHP Code:
PHP Code:
$data[0] = $module
$data
[1] = $id
$data
[2] = $date
$data
[3] = $page
This would hopefully mean i could have
http://mysite.com/blog/13/11/2009/this_is_a_post/page_1 (with the id hidden perhaps)

or a second example with a simpler array say just module and id
http://mysite.com/news/artical_12

Which i would assume would mean that i could have a "complex" navigation structure with very little code compared to a manual method.

Any thoughts on this method?
jerry_louise is offline   Reply With Quote
Old 10-15-2009, 12:50 PM   #4
sneakyimp
Senior Member
 
Join Date: Apr 2003
Location: LA
Posts: 3,720
That latest rewrite you suggest seems perfectly reasonable. I'm sure it's common practice to punt to PHP to handle the incoming request rather than making an elaborate .htaccess file for little advantage. It will certainly result in a much simpler htaccess file.
__________________
Write multiplayer games in AS3/PHP5 with FlashMOG 0.3.1
Find out your worth with the MyPlan Salary Calculator
sneakyimp is offline   Reply With Quote
Old 10-16-2009, 08:36 AM   #5
Ashley Sheridan
Senior Member
 
Join Date: Aug 2008
Posts: 304
Take care with having PHP handle all of this though, as it is much faster to have Apache do it. Depending on the number of requests and the general response you get from your site at the moment, you might be better off leaving most of the work to the .htaccess file.

Just a thought though. Why can't you add the .htaccess to the apache group (sometimes wwwrun or www), allow group write access, and have PHP write the .htaccess file from whatever you're using to create the pages; I presume a CMS?
__________________
Ashley Sheridan
www.ashleysheridan.co.uk
Ashley Sheridan is offline   Reply With Quote
Old 10-16-2009, 08:41 AM   #6
jerry_louise
Senior Member
 
Join Date: Jul 2008
Posts: 139
Quote:
Originally Posted by Ashley Sheridan View Post
Take care with having PHP handle all of this though, as it is much faster to have Apache do it. Depending on the number of requests and the general response you get from your site at the moment, you might be better off leaving most of the work to the .htaccess file.

Just a thought though. Why can't you add the .htaccess to the apache group (sometimes wwwrun or www), allow group write access, and have PHP write the .htaccess file from whatever you're using to create the pages; I presume a CMS?
I am making my own CMS type system, i am looking at using a .htaccess only but i get confused when it comes to different base for the rewrite rule.

All pages link to index.php, ?page=blog or forum or reviews, est. Is where i get confused as they all have slightly different navigation systems that are made to match there respective areas.
jerry_louise is offline   Reply With Quote
Reply

Bookmarks


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

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 08:04 AM.








Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.