• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1127
  • Last Modified:

Apache Rewrite rule seemingly having no effect, no log results either

I am trying to insert a rewrite rule which replaces:

www.domain.com/something/index.php?title=Special:userlogin

with

http://www.domain.com/login

I have placed the following into my httpd.conf file within the virtual host section but nothing is happening at all?

RewriteEngine On
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteRule ^/Special:Userlogin http://%{SERVER_NAME}/login/ [R,L]
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} ^title=Special:Userlogin
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteRule ^(.*)$ /login/ [R,L]

Nothing changes at the browser and when I look into the log I see nothing that relates to this rewrite rule?

Have I done something silly? Are there other directives I need to add or check that they exist in httpd.conf?

Oh, and I have restarted Apache.

Any input much appreciated.

Thanks,
0
pcoghlan
Asked:
pcoghlan
  • 6
  • 5
1 Solution
 
milanmkCommented:
Just try the following and see if it works.

RewriteEngine On
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} ^title=Special:Userlogin
RewriteRule index.php /login/ [R,L]
0
 
pcoghlanAuthor Commented:
Thanks, nearly there. The rule is at least having an effect now which I suppose means one of the previous rules was not being met.

Anyway, here is the current status. I have the following in my httpd.conf file.

RewriteEngine On
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} ^title=Special:Userlogin
RewriteRule index.php /user/login [R,L]

I would expect

www.domain.com/something/index.php?title=Special:userlogin

to end up as

www.domain.com/user/login/

but instead I end up at

www.domain.com/user/login/?title=Special:Userlogin

So, it is diverting me to the user/login BUT leaving the trailing text in place.

Any ideas?

Thanks,
0
 
pcoghlanAuthor Commented:
sorry, one typo. the last line should be:

RewriteRule index.php /user/login/ [R,L]

Note the additional trailing '/' after the login
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
milanmkCommented:
Query string is auto appended to the rewrite rule, if you dont want it then you will need an external redirect like the following.

RewriteEngine On
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} ^title=Special:Userlogin
RewriteRule index.php www.domain.com/user/login/ [L]
0
 
milanmkCommented:
Sorry,

RewriteEngine On
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} ^title=Special:Userlogin
RewriteRule index.php http://%{HTTP_HOST}/user/login/ [L]
0
 
pcoghlanAuthor Commented:
Thanks, tried this with same result.

I do get diverted to the new folder but the '?title=Special:Userlogin' is still there after the URL.

I tried changing the [R,L] to [L] but that results in the user seeing the URL they typed in.

Changing it back to [R,L] means I get to see the new URL.

I hope this all makes sense!
0
 
milanmkCommented:
Try this.

RewriteEngine On
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} ^title=Special:Userlogin
RewriteRule index.php http://%{HTTP_HOST}/user/login/? [R,L]
0
 
pcoghlanAuthor Commented:
Sorry, no luck. I get a 404 with the ? after the login/
0
 
milanmkCommented:
Generally speaking, appending a "?" in the substitution tells mod_rewrite to remove any query string.

Try removing the slash after login if mod_dir is causing any problems.

RewriteEngine On
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} ^title=Special:Userlogin
RewriteRule index.php http://%{HTTP_HOST}/user/login? [R,L]

Do you have any other rewrite rules above this rules?
0
 
pcoghlanAuthor Commented:
That did the trick!

Many thanks for your continued patience.

0
 
milanmkCommented:
Most welcomed.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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