LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache redirect with query string (.htaccess) (https://www.linuxquestions.org/questions/linux-server-73/apache-redirect-with-query-string-htaccess-483728/)

penguintutor 09-15-2006 07:56 AM

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

generic_user 09-16-2006 05:33 PM

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.

penguintutor 09-20-2006 09:45 AM

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.


All times are GMT -5. The time now is 05:46 PM.