I try to rewrite all languages to /en/ on a site. But I do something wrong and do not know what.
All domain request like https://www.shop.com/de/ or https://www.shop.com/ must rewrite to https://www.shop.com/en/
Why I need this? First my shop must be ready in /en/ language. When everything works fine I will add /de/ and then /nl/.
Does someone have a solution for me? Would be very nice.
Here the code I use in htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule https://www.shop.com/de/ https://www.shop.com/en/
RewriteRule https://www.shop.com/nl/ https://www.shop.com/en/
RewriteRule https://www.shop.com https://www.shop.com/en/
RewriteRule https://www.shop.com/ https://www.shop.com/en/
</IfModule>
You cannot match full URLs in RewriteRule.
You can use these rules:
RewriteEngine On
RewriteBase /
RewriteRule ^(de|nl)?/?$ /en/ [L,NC,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Related
I have this rewrite rule in .htaccess:
RewriteRule ^^babysitter/([^/]*)/([0-9]+)/? /hlp/index.php/babysitter/$1/?p=$2 [QSA,L]
So if I write this URL:
localhost/hlp/babysitter/rome/3618
the browser rewrites it like this:
localhost/hlp/babysitter/3618
which is something I don't want, even if it returns correct result.
For completeness I write my whole .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /hlp/
RewriteRule ^index\.php$ - [L]
RewriteRule ^^babysitters/([^/]*)/? /hlp/index.php/babysitters/?resume_location=$1 [QSA,L]
RewriteRule ^^babysitter/([^/]*)/([0-9]+)/? /hlp/index.php/babysitter/$1/?p=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /hlp/index.php [L]
</IfModule>
So I'm trying to redirect incoming connections based on the referrer URL. So for instance if someone was trying to visit:
blog.example.com/category/fancy-stuff
They are already getting redirected to example.com but I want to redirect them to:
example.com/news/category/fancy-stuff
Right now I have this for my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_REFERRER} blog.example.com/category/* [NC]
RewriteRule ^ example.com/news/category/*? [R=301,L]
</IfModule>
Is there a way to use variables or something to just append the proper category to the new URL?
Reorder your Rewrite rules :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERRER} ^blog.example.com/category/.*$ [NC]
RewriteRule ^(.*)$ http://example.com/news/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've to change this url : http://localhost:8888/finance/schedule/?location=new_york
to http://localhost:8888/finance/schedule/location/new_york
It's a wordpress site, my htaccess code is :
RewriteRule ^schedule/location/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\$ schedule/?location=$1
But nothing seems to happen, please suggest.
The whole htaccess file code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /finance/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /finance/index.php [L]
RewriteRule ^schedule/location/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\$ schedule/?location=$1
</IfModule>
This line is stopping it from ever reaching your later rule:
RewriteRule . /finance/index.php [L]
The [L] means "last," as in "this is the last rule to run if it matches."
And \$ looks for a literal $, not the end of the string.
You also have two many matching groups in your rule.
You need something like this, instead (totally untested):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /finance/
RewriteRule ^index\.php$ - [L]
RewriteRule ^schedule/location/([a-zA-Z0-9_-]+?)/?$ /wp-content/themes/financeinstitute/page_schedule.php/?location=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /finance/index.php [L,QSA]
</IfModule>
How can I change my URL from domain.com/sprekers/?spreker=value to domain.com/value with a rewrite rule with wordpress.
I've tried to change it like this
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
than I tested it with the htaccess tester http://htaccess.madewithlove.be If I test it on the tester everything works fine but when I do this on my wordpress site it doesn't work. This is my complete htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
</IfModule>
I think it doesn't work because the /sprekers is already "made" by wordpress how can I fix this?
Cheers
Robin
I think, you need to put your first code after the RewriteBase / rule.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have couple of urls which is generated by wordpress/php
http://mydomain.com/news-2/newsarticle
http://mydomain.com/products/category-2
http://mydomain.com/products/category/products-2
how can I rewrite/redirect any url with -2 to the one without? The result should be
http://mydomain.com/news/newsarticle
http://mydomain.com/products/category
http://mydomain.com/products/category/products
This is what I have so far
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thanks
Add this to you htaccess :
RewriteRule ^(.*)-2(.*)$ /$1$2 [NC,L,R=301]