.htaccess: Replace part of url for a domain - .htaccess

I have this url
www.mydomain.com/aftomelanomenes-sfragides/eos-7-grammes/197430-092399532491-sfragida-trodat-printy-4915-aytomelanomeni-mple-detail
and I would like to replace it with this
www.mydomain.com/aftomelanomenes-sfragides/eos-7-grammes/197430-092399532491-sfragida-trodat-printy-4915-aftomelanomeni-mple-detail
i tried this code to htaccess
RewriteRule ^-aftomelanomeni-?$ -aytomelanomeni-$1 [NC,L]
But it doesn't work

Try to use this pattern:
RewriteRule ^(.+)-aytomelanomeni-(.+)$ http://%{HTTP_HOST}/$1-aftomelanomeni-$2 [R=301,L]

Related

htaccess rewrite problems page.html?{rewrite} --> page.html

I have problem with htaccess rewrite rule.
I have page for example:
www.oldpage.com/55,city.html?partner_id=7
www.oldpage.com/subpage/158,blog.html?partner_id=8
And I want to rewrite this page on:
www.newpage.com/55,city.html
www.newpage.com/subpage/158,blog.html
It is possible? Maybe I must redirect links with .html?partner_id on normal .html, after on newpage?
You can use the QSD flag (query string discard)
RewriteRule .* ww.newpage.com/$1 [NC,QSD]
I solved this problem by adding in .htaccess for newpage.com this code:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^partner_id=([0-9]*)$
RewriteRule ^(.*)$ /$1? [R,L]

.htaccess : write rule with langage parameter for SEO

The goa is to rewrite:
www.example.com/fr/something.php ->www.example.com/something.php?lang=fr
I tried with:
RewriteRule ^.*/fr/(.*)$ http://www.example.com/$1?lang=fr[R,L]
RewriteRule \/fr\/(.*)$ http://www.example.com/$1?lang=fr[R,L,QSA]
RewriteRule /fr/(.*)$ http://www.example.com/$1?lang=fr[R,L,QSA]
Not good:
Any idea ?
Try with:
RewriteEngine on
RewriteRule ^fr/(.*)$ /$1?lang=fr [QSA,L]
I do not think you want a redirect, but only a rewrite (without changing the url)

.htaccess mod_rewrite URL language

I would like to write a rule, that would redirect URL like this:
myweb.com/en/page
to
myweb.com/page.php?lang=en
This code:
RewriteRule ^/(cz|en)/(.*)$ $2?lang=$1 [L]
does not work (error 404). Thanks everyone.
Try this following:
RewriteRule ^/(cz|en)/(.*)$ $2.php?lang=$1 [L]
You dont need to match the leading slash in RewriteRule's pattern on htaccess context :
RewriteRule ^(cz|en)/(.*)$ $2?lang=$1 [L]

Rewrite directory URL with htaccess

I have a directory structure like this:
http://example.com/directory/folder/files/
I want to rewrite the URL with htaccess so that when a user visits:
http://example.com/path/
They are served the files from http://example.com/directory/folder/files/.
Essentially, I want to replace directory/folder/files/ with path/
How can I do this?
I've been trying this at the moment, but it doesnt work, it just adds path infront of the URL:
RewriteCond %{REQUEST_METHOD} =GET
RewriteRule ^directory/folder/files/$ path/%{REQUEST_URI} [L]
The rule you would need is reverse of what you've attempted. Try this rule:
RewriteCond %{REQUEST_METHOD} =GET
RewriteRule ^path/(.*)$ /directory/folder/files/$1 [L,NC]
try adding a slash at the beginning or
RewriteBase /

Rewrite rule in .htaccess and redirect

i would like the url being rewritten automatically from :
hello.com/a-b-c/0/
to:
hello.com/a-b-c/1/
I have a rewrite rule on .htaccess
RewriteRule ([a-zA-Z0-9\.\-]+)/0/?$ $1/1/ [NC,L]
But that doesn't seem to work. may I know what is the issue?
Thanks.
You can try this rule for redirect:
RewriteRule ^([a-zA-Z0-9.-]+)/0/?$ /$1/1/ [R,L]
Or for internal rewrite:
RewriteRule ^([a-zA-Z0-9.-]+)/0/?$ /$1/1/ [L]

Resources