Link to home
Start Free TrialLog in
Avatar of pcoghlan
pcoghlan

asked on

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,
Avatar of milanmk
milanmk

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]
Avatar of pcoghlan

ASKER

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,
sorry, one typo. the last line should be:

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

Note the additional trailing '/' after the login
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]
Sorry,

RewriteEngine On
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} ^title=Special:Userlogin
RewriteRule index.php http://%{HTTP_HOST}/user/login/ [L]
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!
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]
Sorry, no luck. I get a 404 with the ? after the login/
ASKER CERTIFIED SOLUTION
Avatar of milanmk
milanmk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did the trick!

Many thanks for your continued patience.

Most welcomed.