Solved

mod_rewrite

Posted on 2011-02-12
4
275 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

730 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