Tricky mod rewrite - .htaccess

I hope someone can help me, I am looking to help an ex-client with some troubles.
they have images from URL's with this sub-sub structure:
http://images.abc1234.SPECIFIC-DOMAIN.com/image.jpg
Due to a long story I do not completely understand, that sub sub structure exists and now is in peril.
Can anyone point to a solution to rewrite the above into:
http://images.ANOTHER-DOMAIN.com/image.jpg
which would also NOT AFFECT something like this:
images.THIRD-DOMAIN.com/image.jpg
Any help to this challenge would be appreciated.
Thank you and sorry if this is written in bad form, it's not my area of expertise.

this will redirect:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^images.abc1234.SPECIFIC-DOMAIN.com$ [NC]
RewriteRule ^(.*\.(jpg|png|gif))$ http://images.ANOTHER-DOMAIN.com/$1 [L,R=301]

Related

How do a I remove a specific query string in htaccess?

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.

Rewrite url for friendly seo

Does anyone know a working way for this to be done?
Rewrite url http://example.com/index.php?page=the-page to http://example.com/the-page
I hope that someone know how this is done, can't find a working rewriterule.
Thanks.
Found it here..
So if anyone need this too :)
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1

Simple .htaccess rewrite

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

Remove string in .htaccess

I have the following entry in my .htaccess file:
RewriteRule ^blogs$ ?name=data&case=gview&group_id=31%1 [L]
What I do is, I redirect blogs to ?name=data&case=gview&group_id=31
Now what happens is, all my urls are now blogs?id=1 etc, but I need them to stay just ?id=1
How can I remove the blogs from rest of the urls?
This what I came up with, but it doesn't work:
RewriteRule ^blogs?(.*)$ /$1 [L]
EDIT I might be explaining it wrong. I need to change the actual url display of the links. Is that actually possible?
Not sure... but is that what you're looking for ?
RewriteRule ^/?$ /blogs [L,QSA]
What's wrong with just adding a R to your original rule?
RewriteRule ^blogs$ ?name=data&case=gview&group_id=31%1 [L,R=301]
Ok, the answer is pretty much: It can't be done. I just went over my code, added / before main urls and all is working as intended.
Thank you both for suggestions.

Changing /page.php to /page/

I'm trying to change all http://www.mysite.com/filename.php files to show as http://www.mysite.com/filename/ using mod_rewrite, but I seem to be doing something wrong.
Can anyone help out? I'm guessing it's something pretty simple for those that know. Thanks.
An awesome, simple, copy, paste style tutorial
http://www.workingwith.me.uk/articles/scripting/mod_rewrite
Try this:
RewriteEngine On
RewriteRule ^(.+)\.php$ $1/ [L,QSA]

Resources