I've this .htaccess rule.
# Shop-homepage
RewriteRule ABCDEF/fr-CA/$ shop-homepage.php?lang=fr&country=ca&shop=ABCDEF [L,QSA]
RewriteRule ABCDEF/en-CA/$ shop-homepage.php?lang=en&country=ca&shop=ABCDEF [L,QSA]
RewriteRule ABCDEF/en-US/$ shop-homepage.php?lang=en&country=us&shop=ABCDEF [L,QSA]
How can I make ABCDEF insensitive case ?
Thanks.
Use NC flag . NC is use to match both uppercase and lowercase characters in URI :
RewriteRule ABCDEF/fr-CA/$ shop-homepage.php?lang=fr&country=ca&shop=ABCDEF [L,QSA,NC]
RewriteRule ABCDEF/en-CA/$ shop-homepage.php?lang=en&country=ca&shop=ABCDEF [L,QSA,NC]
RewriteRule ABCDEF/en-US/$ shop-homepage.php?lang=en&country=us&shop=ABCDEF [L,QSA,NC]
Related
Hy, I have this rewriteRule to change a /search?key=ok
to /search/ok
from a search bar
RewriteCond %{QUERY_STRING} key=([0-9a-zA-Z_-]+) [NC]
RewriteRule (.*) /search/%1? [R=302,L]
But when I search something with spaces like ok ko
it's just return /search/ok.
What do I have to change to have /search/ok-ko ?
Thanks !
Your regular expression pattern ([0-9a-zA-Z_-]+) matches only alphanumeric characters , you can add \s to your pattern to match a space character in Querystring
RewriteCond %{QUERY_STRING} key=([0-9a-zA-Z\s_-]+) [NC]
RewriteRule (.*) /search/%1? [R=302,L]
i've got .htaccess file:
RewriteEngine on
RewriteRule ^category?$ category.php
RewriteRule ^category/([0-9a-zA-Z]+) category.php?name=$1
Need to even use letters "ě,š,č,ř,ž,ý,á,í,é" etc..
How to do that?
You can use:
RewriteEngine on
RewriteRule ^category?$ category.php [NC,L]
RewriteRule ^category/([^/]+)$ category.php?name=$1 [NC,L]
Which accepts all characters
I have the htaccess rule above:
RewriteRule ^category/([\w-]+)/(\d+)/?$ category.php?categoria=$1&id=$2 [L,QSA,NC]
RewriteRule ^category/([\w-]+)/?$ category.php?categoria=$1&id=1 [L,QSA,NC]
RewriteRule ^category/ allcategories.php
So if I have category/some_name or category/some_name/id it will redirect to category.php.
If I have only category/to allcategories.php.
The problem is urls like this:
category/j.j._name
category/victoria%27s_secret
It has a value (j.j...) and it is redirecting to allcategories.php instead of category.php. What is wrong? is it the special characters? how to solve?
You need to tweak your regex to allow special characters:
RewriteRule ^category/([^/]+)/(\d+)/?$ category.php?categoria=$1&id=$2 [L,QSA,NC]
RewriteRule ^category/([^/]+)/?$ category.php?categoria=$1&id=1 [L,QSA,NC]
RewriteRule ^category/?$ allcategories.php [L,NC]
[^/] will match anything except a /.
I need to change the following url
http://somedomain.com/news/a_sample_news_article.html
to
http://somedomain.com/post/a-sample-news-article
I have this in my htaccess which works, but I am sure it can be improved upon - does anyone have a better solution?
RewriteEngine on
# replace underscores
RewriteRule ^(news)/([^_]*)_+(.*)$ /$1/$2-$3 [L,NC,R=302]
# redirect the directory from news to post
RewriteRule ^news/(.*)$ /post/$1 [R,L]
# remove .html from end of url
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
Any help much appreciated!
To redirect
/news/foo_bar
to
/post/foo-bar
you can use the following rule :
RewriteEngine on
# redirect "/news/foo_bar" to "/foo_bar"
RewriteRule ^news/(.+)$ /$1 [L,R]
#2 replace underscore with hypens
RewriteRule (.*)_(.*) $1-$2 [N,E=uscores:yes]
RewriteCond %{ENV:uscores} yes
RewriteRule ^(.+)$ /post/$1 [L,R]
I want to remove the slash of 1 and only 1 url
this snippet will remove them all
# Remove the trailing slash
RewriteCond %{HTTP_HOST} ^(www.)?example\.com$ [NC]
RewriteRule ^(.+)/$ http://www.example.com/$1 [R=301,L]
but i just want to change
example.com/changeme/
to
example.com/changeme
any ideas how to change this htaccess i have to only do it on one
You could replace (.+) with (changeme) in RewriteRule:
RewriteRule ^(changeme)/$ http://www.example.com/$1 [R=301,L]
This will only match 'changeme' and not everything.
In this way you can also match multiple URLs, including e.g. 'changeother' and 'foobar':
RewriteRule ^(changeme|changeother|foobar)/$ http://www.example.com/$1 [R=301,L]
How about this?
RewriteRule ^changeme/$ http://www.example.com/changeme [R=301,L]
All you need is (as long as this rewrite is only applied to example.com):
RewriteRule ^changeme/$ changeme [R=301,L]