I have been trying to remove the end of a query. I have read and tried many different examples on Stackoverflow without any luck.
My url as follows:
www.[url].com/search?keyword=big&limitstart=0&option=com_virtuemart&view=category
What I am trying to strip is,
&limitstart=0&option=com_virtuemart&view=category"
ensuring to leave the /search?keyword=big as it is.
I seem to have been able to achieve the above by using the following code I found online and have mix-matched:
RewriteCond %{QUERY_STRING} ^(.*)&limitstart=[^&]+&?&option=com_virtuemart&view=category(.*)$ [NC]
RewriteRule ^/?(.*)$ /$1?%1%2 [R=301,L]
I am not certain if this is 100% correct, but it seems to work for me.
Hope this helps someone else looking for a similar solution.
Related
Hello and thanks in advance...
I have a situation where I need to completely remove the query string if it matches a pattern. I've been searching for an answer or even something close. So far, no luck. I've even tried a few things in my htaccess but without success.
The specific query string I need to remove is ?fbclid= and everything that comes after it.
Thank you!
Hard to say what your actual issue is, since you did not share your attempts so far. So we cannot help with those. All I can offer is another example. No idea if that helps.
This implements an internal rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fbclid=
RewriteRule ^ %{REQUEST_URI} [QSD]
Here the variant for an external redirection:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fbclid=
RewriteRule ^ %{REQUEST_URI} [QSD,R=301]
It always is a good idea to start out with a temporary 302 redirection and to only change that to a 301 once you are sure the current solution is final.
So I asked this question before but got none working answer, maybe I defined it in a wrong way.
My question is: How can I remove all / urls from my link.
So for example: the URL right now is: exampledomain.com/a/dashboard.html
But I want it to be: exampledomain.com/ and nothing after it.
So basicly nothing after the example.com/.
Is that possible? I guess it has to be done in the .htaccess file but couldnt find a working rule.
So now it is: exampledomain.com/a/dashboard.html
But I want it to be: exampledomain.com & nothing behind that / when u go to the dashboard.
Thanks for your help
You can try the below rule in .htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule .* / [L,R=302]
I've looked online and couldn't find exactly what I was looking. I tried to combine two different tutorials together but still nothing.
I need an .htaccess rule that changes:
game.php?id=$1&title=$2
to
/game/$1/$2.html
I've gotten it to work with one word as $2 but if there is a space, everything crashed. My current code is
RewriteEngine on
RewriteRule ^game/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ game.php?id=$1&title=$2
Any help will be greatly appreciated.
Thanks,
It looks like your wrote the opposite of what you are asking for. Currently your rewrite will rewrite
/game/$1/$2.html to game.php?id=$1&title=$2
RewriteRule ^game/([^/]+)/([^/]+)/?$ /game.php?id=$1&title=$2 [L]
if you are wanting the other way like you asked it'd look like this:
RewriteCond %{QUERY_STRING} ^id=(.*?)&title=(.*?)$
RewriteRule ^game.php$ /game/%1/%2.html? [L]
If it's only about spaces try adding "\s" to square brackets:
RewriteRule ^game/([A-Za-z0-9-\s]+)/([A-Za-z0-9-\s]+)/?$ game.php?id=$1&title=$2
I have a webpage, which url looks like this:
http://www.mydomain.com/folder/index.php?title=The_title
The only problem is that I want it to look like one of these:
http://www.mydomain.com/folder/The_title
http://www.mydomain.com/folder/The_title.php
I have searched most of a lot and found one solution, which "works":
RewriteEngine on
RewriteRule ^([^/]*)\.html$ /folder/index.php?title=$1 [L]
It does what it should, except the ending has to be ".html" (or ".kl", if you like). This solution won't accept ".php", which gives me a "500 Internal Server Error". Same thing happens if I try it without the extension.
EDIT:
Forgot to mention that the .htaccess file lies in the folder and not the root.
This will work for you.
RewriteEngine On
RewriteRule ^folder/([^/]*)\.php$ /folder/index.php?title=$1 [L]
So, since I couldn't get it to work properly I took the challange and started reading about mod_rewrite, which led to the solution:
RewriteRule ^(\w+)/?$ index.php?title=$1 [L]
If anyone else run into troubles I'll recommend these sites:
more .htaccess tips and tricks..
An In Depth Guide to mod_rewrite for Apache
What I'm trying to do seems very simple, but I did not yet find the solution. The idea is that a specific directory on my server can only be opened through one URL. Currently, the website can be accessed by navigating to http://dir.mydomain.com as well as http://mydomain.com/dir. All links use the first option, but to prevent search engines from detecting duplicate content and my users from getting confused I'd like to simply disable the second option. I would swear that I have read something about a solution some time, but I can't remember it or find it back... Hope you can help me fixing this, thanks in advance!
Why not just redirect with a 301 to dir.mydomain.com so whatever links to the 2nd get mapped to the 1st?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /dir
RewriteRule ^dir http://dir.mydomain.com [R=301]