htaccess add sufix to year. /wp-content/uploads/year-sufix/01/file.jpg - .htaccess

could you help me to rewerite urls?
Now urls looks like:
src="https://example.com/wp-content/uploads/2022/02/file1.png"
src="https://example.com/wp-content/uploads/2019/02/file2.png"
src="https://example.com/wp-content/uploads/2020/02/file3.png"
I'd like them to look like this:
src="https://example.com/wp-content/webp-uploads/2022/02/file1.webp"
src="https://example.com/wp-content/webp-uploads/2019/02/file2.webp"
src="https://example.com/wp-content/webp-uploads/2020/02/file3.webp"
i try something like this, but didn't work :C
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-content/uploads/.+?\.(jpe?g|png|gif)$ /wp-content/webp-uploads/.+?\.webp$ [R=301,L]
</IfModule>
unfortunately htaccess gives me a lot of trouble and I don't know how to write it :/

Related

Too many redirects using .htaccess file to cut and change URL

I've go a .htaccess file on my server with this code:
RewriteEngine on
RewriteRule ^([a-z0-9-]+)? index.php?i=$1 [L]
When I run this I've got something like this:
http://example.com/index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.php?i=XYZ
How to get link look like this:
http://example.com/index.php?i=XYZ
from link look like this
http://example.oom/XYZ/ABC/123
I only need first XYZ to index.php?i=XYZ
Working code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([^/.]+)?$ index.php?i=$1 [L]
</IfModule>

Htaccess rewrite clean categories & articles

I have a URL that looks like this:
example.com/index.php?p=blog&category=blog&article=blog-test
But I'd like to have it look like:
example.com/blog/blog/blog-test
How would I be able to do this with htaccess?
You can use .htaccess:
RewriteEngine on
RewriteRule ^(.+?)/(.+?)/(.+)$ index.php?p=$1&category=$2&article=$3 [L]

Rewrite subfolder to index.php file

i want to rewrite the url http://www.host.com/de/rss to the file http://www.host.com/index.php?type=9000001&L=1
My rewrite rule look like this:
RewriteRule ^de/rss(.*) index.php?type=9000001&L=1
But this does not work. If i delete de/ it works with the corresponding url.
I tried to look for similar questions here on stackoverflow, but that didnĀ“t help.
Use this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^de/rss/?$ index.php?type=9000001&L=1 [L,QSA,NC]
And if doesn't work then please post your full .htaccess in your question.
Maybe you should try this:
RewriteRule ^/de/rss.*$ /index.php?type=9000001&L=1

Htaccess Rewrite second rule not working

I want to rewrite urls like index.php?c=4 & index.php?g=23 into website.com/games/categoryname/id/
and the same thing for the game page website.com/play/gamename/id/
my htaccess file looks like this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9\-_%]+)/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?c=$3
RewriteRule ^([a-zA-Z0-9\-_%]+)/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?g=$3
The problem is that only the first rewrite rule is working, if I comment it, then the second will work too, but never both :(. I'm testing this on MAMP
Can you please help me?
They cannot work both as they have the same condition - you have set two different actions with the same criteria and only the first one is executed.
Ah, I understood what you are trying to achieve:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(games)/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?c=$3 [L]
RewriteRule ^(play)/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?g=$3 [L]
You have to do something like this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^play/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?c=$2
RewriteRule ^games/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?g=$2

Removing a folder name from a url using mod rewrite

I have a url structure that looks like this:
http://www.blahblah.com/community/i/pagename
However, I want to remove the ugly /i/ part. Is this possible with Modrewrite?
Yes, it's possible:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\w+)/(\w+)$ $1/i/$2 [QSA]
</IfModule>

Resources