Forum Moderators: phranque
I saw this thread : [webmasterworld.com...]
About using htaccess to delete all after the % sign.. I tried adapting this but could not manage it... however I know from testing that a similar solution would work.. it just needs to delete all after the? sign... so the URL requested would be:
http://www.example.com/content/1/2/?&referrer=http://www.example.com
but the URL presented would be http://www.example.com/content/1/2
Hope you guys know what I'm talking about.. this is driving me mad :) ( And I'm not that great with .htaccess)
I would really appreciate some help! Thanks!
[edited by: jdMorgan at 2:45 pm (utc) on Aug. 4, 2005]
[edit reason] Examplified. [/edit]
Welcome to WebmasterWorld!
The key here is that the query string (everything following the "?") is not part of a URL, but rather, data appended to the URL to be passed to the resource at that URL. For this reason, it is handled separately by mod_rewrite.
You can clear the query string by appending a "?" to the substitution URL.
In order to avoid an 'infinite' rewrite loop, you should also test the query string to be sure it is non-blank or contains a specific value before rewriting. Otherwise, you'll get a loop.
A simple example would be to rewrite /foo.php?prod=bar to /foo.php:
RewriteCond %{QUERY_STRING} ^prod=bar$
RewriteRule ^foo\.php$ /foo.php? [L]
Jim
Using your code sample and changing it for my site.. I can't get it to do anything.. I changed the prod=bar to the referrer code and the foo.php to the index.php .. however it does not delete anything.
When I tried the code in the thread I mentioned in my first post.. it would delete the URL if I replaced the? with a % in the referrer code which this side appends.. is it not possible to just use modified code for? instead of %?
I am very new to htaccess.. and it is kinda daunting O_o
If not try:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^foo\.html$ /index.php [L]
Since you haven't posted your code, we can't really discuss it.
Jim
That is my current .htaccess so maybe it is interfering with the other code... I must have that code though as it is essential for Mambo (my CMS) to work for search engines..
Things do work though when I tried the code I mentioned in the other thread with the % sign... deleted it right away... just need to figure out a system to delete after? .. I no so little about .htaccess and am finding it quite difficult to interpret the commands..
The following assumes that you want an internal rewrite, and that the second ruleset also applies to the URLs rewritten by the first ruleset.
RewriteCond %{QUERY_STRING} referrer=http://www\.example\.com
RewriteRule ^content/1/2$ /content/1/2?
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php [L]
I would want things which have been rewritten by the first ruleset to be subject to the second as without that the content would not be fetched correctly.
As the site links to different types of content and the (for example):
"content/1/2"
etc changes with each new piece of content, how would I go about accounting for that?
It is best to avoid applying rewrites to all URL-paths, since performance is affected and some very unpleasant side-effects can occur unless it's well thought-out.
The coding is usually easy -- it's defining the problem that's difficult, as this thread demonstrates.
So what, precisely, are the conditions under which you want to remove that query?
Jim
Basically I (or someone else) submits my link to them and then they list my site.. but their script shoves?&referrer=http://www.example.com on the end of my URL. That bit never changes... Just some code to recognise the referring URL, then chop the '?&referrer=http://www.example.com' off the end would be perfect, if it is coming from 1 refering URL.. and it can be recognised.. hopefully it would make things faster?
They could link to any part of the site though and the URL would change significantly... but they will always stick the '?&referrer=http://www.example.com' at the end...