I'm trying to make firendly urls.
My site url is:
domain.pl/index.php?str=prod_big&idk=869&kat=
My .htaccess code is:
RewriteCond %{HTTP_HOST} !^domain\.pl$
RewriteRule ^(.*) http://domain.pl/$1 [R=301,L]
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?str=$1&idk=$2&kat= [L]
But after visiting:
http://domain.pl/prod_big/869.html
nothing happens. What should i do more ?
Related
I am trying to redirect /abc.html to /abc.php but when I did it gives an extra http// and page is not working like http//www.example.de/abc.php don't know from where this HTTP comes.
note: website is not with ssl so domain name is http://example.de
My .htaccess file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.de/$1 [R=301,L]
RedirectPermanent /tour.html /tour.php
With your shown samples/attempts, could you please try following. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
##To serve home page link.
RewriteRule ^/?$ index.php [L]
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^([^.]*)\.html/?$ $1.php [NC,L]
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]
I have a URL
original: https://www.example.com/video/12345/name-of-the-video/
Sometimes users or web crawlers write the URL differently:
https://www.example.com/video/12345/name-of-the-video/65485/
https://www.example.com/video/12345/
https://www.example.com/12345/
I want all 3 URLs to redirect (forward) to the original:
https://www.example.com/video/12345/name-of-the-video/
My current htaccess rule is:
RewriteRule ^video/([0-9]+)/([^/]+)/$ view_video.php?id=$1&dir=$2 [L,QSA]
RewriteRule ^video/([0-9]+)/$ view_video.php?id=$1&dir=fake [L,QSA]
Could you please try following, written based on your shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
##To rewrite URL https://www.example.com/12345/
RewriteRule ^([0-9]+)/?$ view_video.php?id=$1&dir=fake [NC,L]
##To rewrite URL https://www.example.com/video/12345/
RewriteRule ^video/([0-9]+)/?$ view_video.php?id=$1&dir=fake [NC,L]
##To rewrite URL https://www.example.com/video/12345/name-of-the-video/65485/
RewriteRule ^video/([0-9]+)/([\w-]+)/[0-9]+/?$ view_video.php?id=$1&dir=$2 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/view_video\.php [NC]
RewriteCond %{QUERY_STRING} id=([^&]*)&dir=(.*) [NC]
RewriteRule ^(.*) video/%1/%2 [R=301,L]
##To rewrite URL https://www.example.com/video/12345/name-of-the-video/
RewriteRule ^video/([0-9]+)/([\w-]+)/?$ view_video.php?id=$1&dir=$2 [NC,L]
I'm currently attempting to rewrite URLS for my employer's website for hopefully better results in SEO. However, I can't seem to get the url rewrite to work.
I have used this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^myemployerssite.com.au$
RewriteRule (.*) https://www.myemployerssite.com.au/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorDocument 404 https://www.myemployerssite.com.au/page-not-found.php
RewriteRule ^services/civil-construction$ /services.php?serviceid=1 [L]
</IfModule>
I expected, for example, the first service page which is civil construction to have it's URL to be rewritten from https://www.myemployerssite.com.au/services.php?serviceid=1 to https://www.myemployerssite.com.au/services/civil-construction
But the URL remains as https://www.myemployerssite.com.au/services.php?serviceid=1
The redirect from non-www to www is working as intended as is the redirect from to http to https.
Some advice would be appreciated
I changed the order of the rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^services/civil-construction$ /services.php?serviceid=1 [L]
RewriteCond %{HTTP_HOST} ^myemployerssite.com.au$
RewriteRule (.*) https://www.myemployerssite.com.au/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
ErrorDocument 404 /page-not-found.php
Try changing this line
RewriteRule ^services/civil-construction$ /services.php?serviceid=1 [L]
to
RewriteCond %{QUERY_STRING} serviceid=1$
RewriteRule ^services.php$ /services/civil-construction [L,R]
I'm trying to beautify some urls. I configured the htaccess file so my urls are changed:
old url: http://mysite.com/index.php?id=45tye4
new url: http://mysite.com/45tye4
I want now to permanently redirect old urls to new urls. This is what I try with no luck:
RewriteRule ^index.php?id=(.*)$ $1 [R=301,L]
The main problem seems to be the '?' in the url. When I try the same url without ? the redirect works. I also tried other variants with no luck:
RewriteRule ^index.php\?id=(.*)$ $1 [R=301,L]
RewriteRule ^index.php[\?]id=(.*)$ $1 [R=301,L]
Update:
I added the redirection according to anubhava instructions. The redirection works, but unfortunately I get into a redirect loop. I thought [L] flag should solve the redirection loop, but it doesn't.
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^index\.php/?$ /%1? [R=301,L]
RewriteRule ^(.*)$ index.php?id=$1 [L]
RewriteRule matches only REQUEST_URI. You have to use RewriteCond to match Query string
Try this code:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\s/+index\.php [NC]
RewriteCond %{QUERY_STRING} (^|&|\?)id=(.*)(&|$) [NC]
RewriteRule . /%2? [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?id=$1 [L]
This will redirect old URI of /index.php?id=45tye4 to new URI: /45tye4