How can redirect if url contains Chinese characters VS English characters in the same .htaccess file as below:
Chinese characters : www.abcdefg.com/wiki/貨船
Redirect : http://www.abcdefg.com/zh/wiki.php?word=貨船
English characters : www.abcdefg.com/wiki/Cargo_ship
Redirect : http://www.abcdefg.com/en/wiki.php?word=Cargo_ship
Now, I am using the below code, how can I use if condition to join the 2 codes in the same .htaccess file ?
Redirect for English:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^abcdefg.com/wiki/$ [NC]
RewriteRule ^(.*)$ http://www.abcdefg.com/en/wiki.php?word=$1 [L,R=301]
Redirect for Chinese:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^abcdefg.com/wiki/$ [NC]
RewriteRule ^(.*)$ http://www.abcdefg.com/zh/wiki.php?word=$1 [L,R=301]
Does it is possible to use If Else to RewriteRule ?
If $ contains English characters
But I do not know how to write if statement. Can anyone help ?
Below is my try out.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^abcdefg.com/wiki/$ [NC]
<If $ contains English characters>
RewriteRule ^(.*)$ http://www.abcdefg.com/en/wiki.php?word=$1 [L,R=301]
</If>
<Else>
RewriteRule ^(.*)$ http://www.abcdefg.com/zh/wiki.php?word=$1 [L,R=301]
</Else>
Try these rules:
RewriteEngine On
# handle English URL
RewriteRule ^wiki/([a-z0-9_:'",&-]+)/?$ en/wiki.php?word=$1 [L,QSA,NC]
# handle Chinese URL
RewriteRule ^wiki/([^/]+)/?$ zh/wiki.php?word=$1 [L,QSA,NC]
Related
Need help ;)
How to redirect this link?
mydomain.com/selbständige?catid=141&id=141:kredit-für-selbstständige-ohne-schufa
Tested with:
RewriteCond %{QUERY_STRING} ^(.+&)?selbständige?catid=141(&.+)?$
RewriteRule ^/$ http://test.com? [R=301,L]
RewriteCond %{QUERY_STRING} ^(.+&)selbst%E4ndige?catid=141(&.+)?$
RewriteRule ^/$ http://test.com? [R=301,L]
redirect 301 "/selbständige?catid=141&id=141:kredit-für-selbstständige-ohne-schufa" http://test.com
...and so on.
No normal workflow works.
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /selbst.+ndige\?catid=141&id=141:kredit-f.+r-selbstst.+ndige-ohne-schufa [NC]
RewriteRule ^ http://test.com? [L,R]
I used .+ to match against special chars in the uri.
I am trying to add English version to my website in subdomain level as following:
en.mywebsite.com/business-name : This will show the English version of a sub-page.
Right now I have actually achieved it somehow by appending the subdomain to the query string with the following code:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com [NC]
RewriteCond %{HTTP_HOST} !^en\.mywebsite\.com [NC]
RewriteRule (.*) http://www.mywebsite.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^en\.mywebsite\.com
RewriteRule ^(.*)$ http://www.mywebsite.com/$1?language=en [QSA]
The problem is, it is doing it by redirecting the user to www.mywebsite.com/business-name?language=en, but I want to avoid redirection, and pass the "newly generated" query string virtually instead.
Can it be achieved, or does QSA always redirect?
Thanks in advance.
Try changing your last rule from:
RewriteCond %{HTTP_HOST} ^en\.mywebsite\.com
RewriteRule ^(.*)$ http://www.mywebsite.com/$1?language=en [QSA]
to
RewriteCond %{HTTP_HOST} ^en\.mywebsite\.com
RewriteCond %{QUERY_STRING} !language=
RewriteRule ^(.*)$ /$1?language=en [L,QSA]
Basically, i'm trying to redirect all the pages like this
http://www.example.com/page-test-1/page-test-1-2/page-test-1-2-3.html
or
http://www.example.com/page-test-1/page-test-1-2.html
or
http://www.example.com/page-test-1/page-test-1-2/
to the home page :
http://www.example.com/
Here's what I've trying :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.exmaple.com/([^.]+)/
RewriteRule ^(.*) http://www.exmaple.com/ [QSA,L,R=301]
And here's the tester I'm using : http://htaccess.madewithlove.be/
Any way I can do this ? Much appreciated.
This rule should work for you:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.exmaple\.com$ [NC]
RewriteRule ^page-test-1/.+ / [L,R=301,NC]
This will catch anything that is not /anypage.html and redirect it. You need to set the RewriteCond on the REQUEST_URI not the HTTP_HOST.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/([^/]*)\.html$
RewriteRule ^(.*) http://www.example.com/ [QSA,L,R=301]
I think I just need a second pair of eyes for this as I can't see why i'm getting a server error.
RewriteEngine On
RewriteRule ^Gig/([a-zA-Z0-9_-]+)$ gig.php
RewriteRule ^Gig/([a-zA-Z0-9_-]+)/$ gig.php
#allow non caps
RewriteRule ^gig/([a-zA-Z0-9_-]+)$ gig.php
RewriteRule ^gig/([a-zA-Z0-9_-]+)/$ gig.php
Edit:
I have now viewed the log and the reason is there are far too many internal redirects. I myself am not too competent at mod_rewrites etc so please have a look.
#redirect so home page shows /Home
Redirect /home.php http://localhost/Home
#add php extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Redirect /home.php http://localhost/Home
# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.*)\.php /$1 [R=301,L]
#redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.^([a-zA-Z0-9_-]+)$ [NC]
RewriteRule ^(.*)$ http://^([a-zA-Z0-9_-]+)$1 [L,R=301]
#remove trailing slash
RewriteEngine on
RewriteRule ^(.*)/$ /$1 [L,R=301]
#allow artistprofile nice url
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/?$ artist_profile.php
#info nice url
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/[Aa]bout/?$ artist_about.php
#gigs nice url
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/[Gg]igs/?$ artist_gigs.php
#tracks nice url
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/[Tt]racks/?$ artist_tracks.php
#gig nice url
RewriteEngine On
RewriteRule ^[Gg]ig/([a-zA-Z0-9_\-]+)/?$ gig.php
That's all the rewrites in the .htaccess file
Edit:
The problem is the adding PHP extension part
#add php extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I think its due to the ([a-zA-Z0-9_-]+) being after the file name.
You need to escape your - characters when they're inside brackets. You can also shorten your code to the following:
RewriteEngine On
RewriteRule ^[Gg]ig/([a-zA-Z0-9_\-]+)/?$ gig.php
# Escape it! ^^
Why can we shorten it like this?
[Gg] means "The character G or g"
/? means "/ repeated 0 or 1 time"
ive this rules at htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.com [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^warcraft$ www.site.com/forumdisplay.php?f=480 [R=301,NE,NC,L]
issue happend when redirect warcraft its redirect to
http://www.site.com/home/site/public_html/www.site.com/forumdisplay.php?f=480
any tip ?
I suppose you want to redirect it to http://www.site.com/forumdisplay.php?f=480
If so put it in your .htaccess file:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^warcraft$ http://www.site.com/forumdisplay.php?f=480 [R=301,NE,NC,L]
You must provide the full URL including protocol in your rule, in this case http://www.site.com/.....