Solved

mod_rewrite

Posted on 2011-02-12
4
242 Views
Last Modified: 2012-05-11
Hi Guys,

Wondering if you can help shed some light on my problem,

At the moment im makng a system where i have
http://url/index.php?page=cnt_name

sometimes i  then need to pass variables to pages if i want to skip
http://url/index.php?page=cnt_name&funct=1&blah=2

i have attached my htaccess file,

is there a way that i can have it so

http://url/page

but then if i want to add variables it can be

http://url/page?variable=1&variable=2&blah=3

without having to create a rule within htaccess file for each page?

Best Regards
ben



RewriteEngine on
###################################################
# Do not process images or CSS files further      #
###################################################
# No more processing occurs if this rule is       #
# successful                                      #
###################################################

RewriteRule \.(css|jpe?g|gif|png)$ - [L]


RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]

Open in new window

0
Comment
Question by:Benji_
  • 2
4 Comments
 
LVL 26

Assisted Solution

by:arober11
arober11 earned 100 total points
ID: 34880554
Simple just add a QSA - "Query String Append" flag to a base rule e.g.

RewriteRule ^/?page$   /index.php?page=cnt_name  [QSA,L]
0
 
LVL 2

Author Comment

by:Benji_
ID: 34882202
Hi,

i tried the above code, now i think i might just be besing stupid

the first bit how dows that understand what  cnt_name is  becuase cnt_name changes depending on what the page variable is, and how to you apend a variable to a string?

Best regards
ben
0
 
LVL 5

Accepted Solution

by:
onemadeye earned 400 total points
ID: 34921764
Try this:

RewriteEngine on
RewriteRule ^(.*)$   index.php?page=$1  [QSA,L] 

Open in new window


Any variables that follows should be not a problem.

Example:
* http://url/index.php?page=cnt_name&var1=text1&var2=text2
(called as) http://url/cnt_name?var1=text1&var2=text2

** http://url/index.php?page=newpage&var1=text1&var2=text2
(called as) http://url/newpage?var1=text1&var2=text2
0
 
LVL 2

Author Closing Comment

by:Benji_
ID: 35194581
Thanks Guys
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now