Need help removing special characters rewrite htaccess - apache

Struggling with a 301 redirect in htaccess after changing my links on my blog.
I have the following code in htaccess today:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^.*$ http://example.com%{REQUEST_URI} [R=301,L]
RewriteRule ^sitemap.xml$ sitemap.php [L]
Rewriterule ^blog/(.+)/(.+).html$ ./blog/view/blog.php?page=$1&mode=$2 [NC]
Rewriterule ^blog/(.+).html$ ./blog/blog.php?page=$1 [NC]
Rewriterule ^blog/(.+)/$ ./blog/view/blog.php?page=$1 [NC]
Rewriterule ^blog/$ ./blog/blog.php [NC]
RewriteCond %{REQUEST_FILENAME} !-f
Rewriterule ^blog/(.+)/(.+)$ ./blog/view/blog.php?page=$1&mode=$2 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^blog/(.+)$ ./blog/blog.php?page=$1 [NC]
The problem is that I´ve now in php converted special characters like 'åäö' to 'aao' but the old links to my old posts has no redirect to the new links.
Can someone please help me out here.

Here is an example of a simple 301 Redirect that I based the following code from.
Here is an example of redirection based on extension to fit your requirement.
RewriteEngine On
RewriteCond %{REQUEST_URI} .html$
RewriteRule ^blog/(.*).html$ /blog/blog.php?page=$1[R=301,L]

Related

RewriteRule - remove params keys and keep values in address bar

RewriteEngine ON
RewriteRule ^video$ video.php [L]
the above line works
example.com/video is interpret as example.com/video.php
now I need example.com/video?id=5&s=lorem-ipsum
to interpret as example.com/video/5/lorem-ipsum - and vice versa
RewriteCond %{THE_REQUEST} video?id=([^\s&]+)&s=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=301,L]
RewriteRule ^([\w-]+)/([\w-]+)/?$ video?id=$1&s=$2 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ video?/$1/$2 [L,QSA]
doesn't work - in both directions
pls help
With your shown attempts, please try following .htaccess rules file. These rules are assuming you want to infernally rewrite to index.php you can change php file name in 2nd set of rules as per your requirement.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##External redirect Rules from here..
##Redirect 301 to example.com/video/5/lorem-ipsum from example.com/video?id=5&s=lorem-ipsum
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/(video)\?id=([^&]*)&s=(\S+)\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
##Internal rewrite for example.com/video?id=5&s=lorem-ipsum
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^video/([^/]*)/(.*)/?$ index.php?id=$1&s=$2 [QSA,NC,L]

.htaccess - Redirect domain/lang/ to subdomain for each language

I've been struggling with this for weeks and I can't get to the solution, I have to make a redirect in .htaccess of a multi-language website with all its pages following the same structure but with a subdomain for each language. In the following way that is valid for http as https:
domain.es/es/allpages to es.subdomain.com/allpages
domain.es/pt/allpages to pt.subdomain.com/allpages
domain.es/de/allpages to de.subdomain.com/allpages
domain.es/fr/allpages to fr.subdomain.com/allpages
domain.es/en/allpages to eu.subdomain.com/allpages
Any ideas?
I have tried the following but not sure if it is correct:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) https://es.subdomain.com/%1 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/pt/(.*)$
RewriteRule ^(.*) https://pt.subdomain.com/%1 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/fr/(.*)$
RewriteRule ^(.*) https://fr.subdomain.com/%1 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/de/(.*)$
RewriteRule ^(.*) https://de.subdomain.com/%1 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/en/(.*)$
RewriteRule ^(.*) https://eu.subdomain.com/%1 [R=301,NC]
Thanks a lot!!!!
Based on your shown samples, could you please try following. Please make sure you clear your browser cache before you test your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.es$ [NC]
RewriteRule ^(es|pt|de|fr|en)/(.*)/?$ http://$1.subdomain.com/$2 [NE,R=301,NC,L]

htaccess rewrite log to multiple php files

I need help in solving the issue with my htaccess rewrite for multiple php file. No matter what I do the the last condition of vod movie is not working and always point to the first php file new.php . The first three are working fine because they point to same file. I have read in here that they shouldn't be ambiguous but I don't know how to do it or solve it. Please help me thanks.
RewriteEngine ON
RewriteBase /
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^live/([^/]*)/([^.]*)/([^/]*)\.m3u8/?$ new.php?code=$1&c=$3&type=m3u8 [NC,L]
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^live/([^/]*)/([^.]*)/([^/]*)\.ts/?$ new.php?code=$1&c=$3&type=ts [NC,L]
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^([^/]*)/([^.]*)/([^/]*)?$ new.php?code=$1&c=$3 [NC,L]
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^movie/([^/]*)/([^.]*)/([^/]*)\.mp4/?$ /vod.php?code=$1&c=$3 [NC,L]
Could you please try following, based on your shown samples only. Please do clear your browser cache before testing URLs.
RewriteEngine ON
RewriteBase /
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^live/([^/]*)/([^/]*)/([^.]*)\.m3u8/?$ new.php?code=$1&c=$3&type=m3u8 [NC,L]
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^live/([^/]*)/([^/]*)/([^.]*)\.ts/?$ new.php?code=$1&c=$3&type=ts [NC,L]
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^movie/([^/]*)/([^/]*)/([^/]*)/([^.]*)\.mp4/?$ vod.php?code=$1&c=$3 [NC,L]
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ new.php?code=$1&c=$3 [NC,L]

Change htaccess for subdomains

I have a site that works as a Romanian dictionary. Let's call it www.mysite.ro. I managed to do all the redirection for the main site (mysite.ro -> www.mysite.ro, mysite.ro/index.php -> www.mysite.ro) and also for the parameters through this topic of stackoverflow.
Now I would like to include an english dictionary. For this I have created a subdomain: english.mysite.ro. Now I would like to create the following redirects:
english.mysite.ro/index.php should redirect to english.mysite.ro
english.mysite.ro/index.php?cuvant=strong&form=care-incepe-cu ->
english.mysite.ro/care-incepe-cu/strong
My current .htaccess file is:
RewriteRule ^declinare/([^/]+)/? declinare.php?cuvant=$1 [L,NC,QSA]
RewriteRule ^conjugare/([^/]+)/? conjugare.php?cuvant=$1 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]*)/?$ definitie.php?forma=$1&cuvant=$2 [L,QSA]
RewriteCond %{HTTP_HOST} ^toatecuvintele\.ro$ [OR]
RewriteCond %{HTTP_HOST} ^www\.toatecuvintele\.ro$
RewriteRule ^index\.php$ "http\:\/\/www\.toatecuvintele\.ro\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^toatecuvintele.ro$
RewriteRule ^/?$ "http\:\/\/www\.toatecuvintele\.ro\/" [R=301,L]
To this, I tried to add the following line, for my first question, but with no success:
RewriteCond %{HTTP_HOST} ^english.toatecuvintele.ro$
RewriteRule ^index\.php$ "http\:\/\/english\.toatecuvintele\.ro\/" [R=301,L]
Any ideas would just be great!
Thank you

getting htaccess rewrite rules to rewrite only specific urls

I only want to rewrite this specific url:
http://www.website.co.uk/php/project.php?project=anythingHere
to
http://www.website.co.uk/php/project/anythingHere
this works fine but when I go to http://www.website.co.uk/php/project/anythingHere
it has changed all the links as well (style sheets, javascript, hyperlinks... things I don't want to change). for example:
http://www.website.co.uk/php/index.php
to
http://www.website.co.uk/php/project/index.php
This is what I have already
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website.com\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.website.com\.co\.uk$
RewriteRule ^clients$ "http\:\/\/website.com\.co\.uk\/billing\/index\.php" [R=301]
RewriteRule ^project/([^/]*)$ /php/project.php?project=$1
Can you try this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?website\.co\.uk$ [NC]
RewriteRule ^clients/?$ http://website.co.uk/billing/index.php [NC,L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(php/project)\.php\?project=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(php/project)/([^/]+)/?$ /$1.php?project=$2 [L,QSA,NC]