We help IT Professionals succeed at work.

How to change the Url using htaccess redirect

Medium Priority
284 Views
Last Modified: 2012-05-12
Im trying to change the following Url by using a RewriteRule  

RewriteRule ^(.*)desktop=1$                  http://www.locksmith-dalycity.com/  [NC,R=301]

the url is:http://www.locksmith-dalycity.com/?desktop=1


Its not working what am I missing?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
Do you have any other rules above this one which might be circumventing this rule? What about RewriteCond's? Any of those immediately before this rule?

Author

Commented:
I dont htink  I just changed the location for the begining of the file and its still doesnt work. Its problably in the syntav I wrote? maybr I missed something or didnt write it good?
You just want to remove the query string?

Try this.

RewriteCond %{QUERY_STRING} desktop=1
RewriteRule ^$ /?

Open in new window


Author

Commented:
no its not working
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
What does your rewrite log show?

Author

Commented:
mm where can I find a  rewrite log?
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
What is your OS?

Author

Commented:
linux

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
I believe it would be under /var/log/apache2 (apache2 may be different if you're running an earlier version of Apache). However, the path is configured through the config file for Apache, so you may want to consult there. The logging has to be turned on either in your apache config file or in one of your .htaccess files also. For example, on my system, I have the following entry in my Apache config file:

RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 9

Open in new window


which means I will be loggin to the file "rewrite.log" under the directory "/var/log/apache2". A log level of 9 means everything will be logged (which will degrade system performance, so only use for short term). A level of 0 means no logging. With the setting above, here is an example of what gets logged:

127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d3378f60/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/test.php -> test.php
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d3378f60/initial] (3) [perdir /var/www/] applying pattern '^.*$' to uri 'test.php'
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d3378f60/initial] (2) [perdir /var/www/] rewrite 'test.php' -> 'testing.html'
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d3378f60/initial] (3) [perdir /var/www/] add per-dir prefix: testing.html -> /var/www/testing.html
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d3378f60/initial] (2) [perdir /var/www/] strip document_root prefix: /var/www/testing.html -> /testing.html
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d3378f60/initial] (1) [perdir /var/www/] internal redirect with /testing.html [INTERNAL REDIRECT]
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d33820f8/initial/redir#1] (3) [perdir /var/www/] strip per-dir prefix: /var/www/testing.html -> testing.html
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d33820f8/initial/redir#1] (3) [perdir /var/www/] applying pattern '^.*$' to uri 'testing.html'
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d33820f8/initial/redir#1] (2) [perdir /var/www/] rewrite 'testing.html' -> 'testing.html'
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d33820f8/initial/redir#1] (3) [perdir /var/www/] add per-dir prefix: testing.html -> /var/www/testing.html
127.0.0.1 - - [04/Nov/2011:15:48:39 --0400] [localhost/sid#7f43d30abd50][rid#7f43d33820f8/initial/redir#1] (1) [perdir /var/www/] initial URL equal rewritten URL: /var/www/testing.html [IGNORING REWRITE]

Open in new window

AWS System Administrator
CERTIFIED EXPERT
Commented:
Do you have any conditions set? If your .htaccess file is just that one line with the rewriterule, then it will not work. Think of it as an If-Then statement, and in this case you've only said "then do this". Without having a condition, the rule gets ignored.
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
@Hellmark
Without having a condition, the rule gets ignored.
That is not accurate. A condition is just a further restriction. For my post immediately above yours, here is my RewriteRule:

RewriteEngine On

RewriteRule ^.*$ testing.html

Open in new window


As you can see above, the rule worked just fine  = )
Keith BrownAWS System Administrator
CERTIFIED EXPERT

Commented:
Hmm, well, learn something new every day. I know from past experience, I couldn't get things working without a condition, but must have done something wrong.

Author

Commented:
I didnt try the soloution at the end. So at this point Im just assuming its working

Explore More ContentExplore courses, solutions, and other research materials related to this topic.