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]
Related
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]
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)
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]
I have a url like : www.mysite.com/truck/user/?l=2&lang=en&online=450215437
i want to rewrite like : www.mysite.com/truck/?l=2&lang=en&online=450215437
Mean i dont want user folder apear on url .
I have try this in .htaccess file but not work :
RewriteEngine on
RewriteRule ^(user\/\?l=([0-9]*)&lang=(.*?)&online=([0-9]*))$ index.php?l=$1&lang=$2&online=$3 [L]
Please help me :s
That rule is wrong since RewriteRule doesn't match QUERY_STRING. Use this rule instead:
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(truck/)user/?$ $1 [L,NC]
QUERY_STRING will be carried over automatically.
Ok, im pretty new at this and I would really appreciate some help, thanks!
How can i rewrite this in .htaccess correctly?
So I have a query string in my url:
/?url=contact
All i want to do is remove the query string
/contact
Help? I scoured google and I'm learning the syntax right now, but the fact remains..I dont know how to do it just yet. Thanks to all
This was my solution:
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
Try this:
RewriteEngine On
RewriteRule ^(.*)$ /index.php?url=$1 [L]
To a user on your site, they will see and navigate to this:
http://example.com/contact
But the real page would be something like this:
http://example.com/index.php?url=contact
This bit, [L], tells the server that this is the last line of the rewrite rule and to stop.
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule index.html %1
(or whatever if it's not index.html, index.php, whatever)
You need to capture the query string, which is not looked at by RewriteRule normally, and use the %1 back reference, not $1 as you would in a capture in a RewriteRule
Before: https://example.com/index.php?user=robert
RewriteEngine On
RewriteRule ^user/([^/]+)?$ index.php?user=$1 [L,QSA]
After: https://example.com/user/robert