LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-23-2012, 09:11 PM   #1
varig203
LQ Newbie
 
Registered: Apr 2012
Distribution: centos
Posts: 2

Rep: Reputation: Disabled
mod_rewrite append to URL


Good day everyone,

I've been trying to find a way to append a header to a URL for a few days; however, I have not been successful (I am quite new to apache/mod_rewrite).
I have a header that is called UserPreferences and contains the following ?size=large&color=green (size and color are user specific attributes) . Users connect to my Apache web server using the following base url http://example.com, I'd like to rewrite the url so that it looks like http://example.com/?size=large&color=green.

Thanks in advance,

VG
 
Old 04-24-2012, 10:02 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
I don't think you actually mean 'header'. A header is something the website send to your browser, like "Content-Type: text/html; charset=utf-8". In addition, you're just passing variables to a script! It would be far easier to edit your script to include the lines

PHP Code:
if(empty($_GET['size'])) $size='large';
if(empty(
$_GET['color'])) $color='green'
or similarly in a non-PHP language.

However, if you have to do it with .htaccess (which as before, I don't recommend - I suspect you're asking the wrong question) then I believe the following will work:

Code:
RewriteEngine on
RewriteRule ^$ /index.php?size=large&color=green [L]
Hope this helps,
 
Old 05-14-2012, 04:20 PM   #3
varig203
LQ Newbie
 
Registered: Apr 2012
Distribution: centos
Posts: 2

Original Poster
Rep: Reputation: Disabled
Sorry, I did not provided enough info for my question. Here is how I solved my problem:

RewriteCond %{LA-U:ENV:UserPreferences} (.+)
RewriteRule (.*) http://example.com/%1 [L]

Last edited by varig203; 05-14-2012 at 04:21 PM.
 
Old 05-15-2012, 11:59 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Well done for solving your problem! Please mark the thread as 'SOLVED' so other people know that there's a solution in the thread.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with removing %20 from URL with mod_rewrite jnyunt Linux - Server 12 07-27-2020 05:38 AM
Rewriting a URL with mod_rewrite PlymWS Linux - Server 9 12-17-2011 05:42 PM
mod_rewrite remove subdirectories from url xjx424 Programming 4 04-25-2011 04:46 PM
mod_rewrite url redirection sqn Linux - Software 2 10-04-2006 08:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration