I want to make redirects from urls like
/test/112321 to /test/
/test/test2/1311223 /test/test2/
There are only digits in the end of the url.
Now i have
RewriteCond %{HTTP_HOST} ^(.*)([0-9]*)/$ [NC]
RewriteRule ^(.*)/([0-9]*)$ http://%1/$1/ [R=301,L]
but it doesn't work.
Could you help me with this?
You don't need RewriteCond %{HTTP_HOST} as you're matching REQUEST_URI which you can do in RewriteRule itself.
You can use this rule in site root .htaccess:
RewriteEngine On
RewriteRule ^(.+)/([0-9]+)/?$ /$1/ [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^(.*)/([0-9]+)/?$
rather than:
RewriteCond %{HTTP_HOST} ^(.*)([0-9]*)/$
You can also use RedirectMatch
RedirectMatch 301 ^/(.+)/([0-9]+)/?$ /$1
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 have this rule for rewriting all subdomains to some URL, but I would like to edit it to rewrite all subdomains except subdomain "m".
RewriteCond %{HTTP_HOST} ^(.*)\.myweb\.cz
RewriteRule ^(.*)$ http://myweb.cz/adverts/%1/$1 [L,NC,QSA,R=301]
Thanks everyone.
You can add a negative lookahead in your condition to avoid matching m.:
RewriteCond %{HTTP_HOST} ^((?!m\.)[^.]+)\.myweb\.cz$ [NC]
RewriteRule ^(.*)$ http://myweb.cz/adverts/%1/$1 [L,R=301]
Try this htaccess
RewriteCond %{HTTP_HOST} !^m\.myweb\.cz$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.myweb\.cz$
RewriteRule ^(.*)$ http://myweb.cz/adverts/%1/$1 [L,NC,QSA,R=301]
I'm not sure if what I want to achieve is even possible via .htaccess, I have trawled Google without any luck.
I have a pile of redirects to apply to a multi-store website which means that two domains will share the same .htaccess file. The problem that I have is that the redirects for each domain are conflicting with each other.
Is it possible set up the equivalent of a php 'if' statement within the .htaccess file without adding a condition before each redirect?
<If domain = http://www.example-1.com>
RedirectMatch 301 ^/en/1-2-drive-torque http://www.example-1.com/90-britool-expert-torque-wrenches
RedirectMatch 301 ^/en/10-Britool http://www.example-1.com/24-britool-expert-spanners
RedirectMatch 301 ^/en/11-Britool http://www.example-1.com/78-britool-expert-combination-spanners
RedirectMatch 301 ^/en/12-Britool http://www.example-1.com/77-britool-expert-ratchet-spanners
RedirectMatch 301 ^/en/13-Britool http://www.example-1.com/79-britool-expert-open-end-spanners
etc...
</If>
<If domain = http://www.example-2.com>
RedirectMatch 301 ^/en/1-2-drive-torque http://www.example-2.com/390-britool-expert-torque-wrenches
RedirectMatch 301 ^/en/10-Britool http://www.example-2.com/624-britool-expert-spanners
RedirectMatch 301 ^/en/11-Britool http://www.example-2.com/478-britool-expert-combination-spanners
RedirectMatch 301 ^/en/12-Britool http://www.example-2.com/677-britool-expert-ratchet-spanners
RedirectMatch 301 ^/en/13-Britool http://www.example-2.com/779-britool-expert-open-end-spanners
etc...
</If>
Any help or advice will be very much appreciated
You'll need to use mod_rewrite for this instead and use the %{HTTP_HOST}. Unfortunately, there's no way to create "if" containers like you have in your example. You'll need to duplicate the condition each time:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example-1\.com$ [NC]
RewriteRule ^en/1-2-drive-torque /90-britool-expert-torque-wrenches [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-1\.com$ [NC]
RewriteRule ^en/10-Britool /24-britool-expert-spanners [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-1\.com$ [NC]
RewriteRule ^en/11-Britool /78-britool-expert-combination-spanners [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-1\.com$ [NC]
RewriteRule ^en/12-Britool /77-britool-expert-ratchet-spanners [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-1\.com$ [NC]
RewriteRule ^en/13-Britool /79-britool-expert-open-end-spanners [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-2\.com$ [NC]
RewriteRule ^en/1-2-drive-torque /390-britool-expert-torque-wrenches [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-2\.com$ [NC]
RewriteRule ^en/10-Britool /624-britool-expert-spanners [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-2\.com$ [NC]
RewriteRule ^en/11-Britool /478-britool-expert-combination-spanners [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-2\.com$ [NC]
RewriteRule ^en/12-Britool /677-britool-expert-ratchet-spanners [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example-2\.com$ [NC]
RewriteRule ^en/13-Britool /779-britool-expert-open-end-spanners [L,R=301]
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/.....
Trying to get a simple 301 redirect with htaccess using this code:
Redirect 301 /cat/radiator-cages/product/radiator-support-cage/ http://www.mysite.com/product/radiator-cages/custom-radiator-support-cage/
The results are sending me to
http://www.mysite.com/product/radiator-cages/custom-radiator-support-cage/?page=cat/radiator-cages/product/radiator-support-cage
Any idea what I'm doing wrong?
Thanks in advance for any help.
--Update--
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteRule ^product/(.*)/(.*)/$ /index.php?page=product&parent_url=$1&product=$2 [L,NC]
Redirect 301 /cat/radiator-cages/product/radiator-support-cage/ http://www.mysite.com/product/radiator-cages/custom-radiator-support-cage/
I suggest trying to use the Redirect 301 statement first.
Your htaccess should then look somthing like this
Redirect 301 /cat/radiator-cages/product/radiator-support-cage/ http://www.mysite.com/product/radiator-cages/custom-radiator-support-cage/
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteRule ^product/(.*)/(.*)/$ /index.php?page=product&parent_url=$1&product=$2 [L,NC]
Edit:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteRule ^/cat/radiator-cages/product/radiator-support-cage/$ http://www.mysite.com/product/radiator-cages/custom-radiator-support-cage/ [R=301,L]
RewriteRule ^product/(.*)/(.*)/$ /index.php?page=product&parent_url=$1&product=$2 [L,NC]
http://www.gerronmulder.com/common-seo-rewrite-rules-for-apache-using-htaccess/