[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

mod_rewrite

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
Benji_
Asked:
Benji_
  • 2
2 Solutions
 
arober11Commented:
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
 
Benji_Author Commented:
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
 
onemadeyeCommented:
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
 
Benji_Author Commented:
Thanks Guys
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now