LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-15-2006, 08:56 AM   #1
penguintutor
Member
 
Registered: Jun 2006
Location: UK
Distribution: Ubuntu, Mandriva, Redhat and Fedora
Posts: 118

Rep: Reputation: 15
Apache redirect with query string (.htaccess)


I am wanting to create some user friendly urls that redirect to dynamic pages (with query string values).

I can do want I want on my local server using Apache mod_rewrite, however I need to apply this to a hosted server.

The hosted server allows .htaccess to use the mod_alias commands (e.g. RedirectMatch), but not mod_rewrite. Whenever I add:
Code:
RewriteEngine on
RewriteRule ^/easy$ /phpscript.php?doc=213
then it appears to be ignored.

I tried using a RedirectMatch e.g.:
Code:
RedirectMatch permanent ^/easy$ http://www.mydomain.com/phpscript.php?doc=213
but when I try to do to the http://www.mydomain.com/easy I end up with: http://www.mydomain.com/phpscript.php%3fdoc=213 which gives an error.

Is there any way to keep the query string using RedirectMatch, or is there some other way of achieving this?

Thanks
 
Old 09-16-2006, 06:33 PM   #2
generic_user
Member
 
Registered: Sep 2006
Location: San Francisco, Ca.
Distribution: Redhat/Fedora/CentOS
Posts: 39

Rep: Reputation: 15
Quote:
Originally Posted by penguintutor

but when I try to do to the http://www.mydomain.com/easy I end up with: http://www.mydomain.com/phpscript.php%3fdoc=213 which gives an error.

Is there any way to keep the query string using RedirectMatch, or is there some other way of achieving this?

Thanks
From the mod_alias docs:
http://httpd.apache.org/docs/2.0/mod/mod_alias.html

Quote:
mod_alias is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite.
Odd they wouldn't enable mod_rewrite... I suppose you could always write a php script to listen in on the "easy" urls and redirect accordingly... Perhaps even write one script and use symlinks. One of the env variables should tell you the uri, and from that you should be able to redirect.
 
Old 09-20-2006, 10:45 AM   #3
penguintutor
Member
 
Registered: Jun 2006
Location: UK
Distribution: Ubuntu, Mandriva, Redhat and Fedora
Posts: 118

Original Poster
Rep: Reputation: 15
I also thought it was odd that mod_alias was available, but mod_rewrite was not. I therefore contacted my hosting company and although they were not able to help in fixing the problem they did confirm that mod_rewrite was enabled.

I've therefore being playing around with the rule and I've found the problem.

Although the example code was correct for use in httpd.conf (or equivalent vhost file)

Code:
RewriteEngine on
RewriteRule ^/easy$ /phpscript.php?doc=213
it is not for .htaccess. Instead the entry should have been (note the missing / at the start of the regexp).

Code:
RewriteEngine on
RewriteRule ^easy$ /phpscript.php?doc=213
I suspect that this is because the .htaccess is already in the / directory it applies to rewrite rules relative to that. I did not realize that this was how it worked, I thought it was always absolute to the virtual host.

So all working correctly now. Thanks for your help.
 
  


Reply

Tags
apache, htaccess, modrewrite


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
Grep string and redirect the rest to a file twantrd Programming 6 06-02-2006 08:37 PM
htaccess 'redirect permanent' failing mikeindo Linux - Networking 0 07-07-2005 02:05 AM
Perl/regexp help... - query string parsing... lowpro2k3 Programming 4 05-11-2005 06:18 PM
mysql query for multibyte string onnyloh Programming 3 12-03-2004 09:29 PM
Htaccess with a redirect Diode Linux - Networking 0 10-28-2003 07:23 PM


All times are GMT -5. The time now is 07:59 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration