?
Solved

mod_rewrite

Posted on 2011-02-12
4
Medium Priority
?
287 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 400 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 1600 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

752 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