I have the following redirects:
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^id=409$
RewriteRule ^(.*)$ http://www.domain.eu/index.php\?id=4 [R=301,L]
RewriteCond %{REQUEST_URI} foo_Bar\.pdf$ [NC]
RewriteRule ^(.*)$ http://www.domain.eu/index.php\?id=4 [R=301,L]
The first one works fine.
But the second one is not directing, when I open this url: domain.eu/fileadmin/images/foo_Bar.pdf (showing an 404 instead, thats why I want to redirect).
I've also tried to add a ^(.*) before the filename, but it doesnt work either. I've even tried to enter full url as the request uri, no luck. What am I missing?
Thanks
It will redirect www.yourdomain.com/index.php?id=409 to http://www.domain.eu/index.php?id=4
And the second will redirect if your site address ends with .foo_Bar.pdf redirects to http://www.domain.eu/index.php?id=4
You need to change the second one to:
RewriteCond %{REQUEST_URI} foo_Bar\.pdf$ [NC]
RewriteRule ^(.*)$ http://www.domain.eu/index.php\?id=4 [R=301,L]
Related
I have multiple subdomains that are working with a redirect, but bad for SEO
RewriteRule ^([a-zA-Z0-9&:_-]+)/actions$ http://$1.actions.mydomain.nl [R=301,L]
I want to redirecting to:
http://$1.mydomain.nl/actions
but here i get a 404 error.
How to make the right rule for this?
I assume that your rule looks like this:
RewriteRule ^([a-zA-Z0-9&:_-]+)/actions$ http://$1.mydomain.nl/actions [R=301,L]
So the destination becomes http://subdomain-name.mydomain.nl/actions. So the first thing you need is to make sure a DNS entry is setup to point subdomain-name.mydomain.nl to the right IP address/server. Then on the actual server you need to make sure that the requests are routed to the right place. So assuming that the actual resource is /subdomain-name/actions, you'd need:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain.nl$ [NC]
RewriteRule ^actions$ /%1/actions [L]
This is the complete code i have:
RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9&:_-]+).actions.mydomain.nl$ [NC]
RewriteRule ^$ file.php?seo_naam=%1 [L,QSA]
This is working,but multiple(2 level) subdomains are not a good thing for seo.
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9&:_-]+).actions.mydomain.nl$ [NC]
but i want to change this to:
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9&:_-]+).mydomain.nl\actions$ [NC]
does not work
the thing is that the file.php?seo_naam=%1 should be loaded otherwise it will not work.
I have this link: http://www.domain.com.mk/lajmi.php?id=2790,
and i want to change it to http://www.domain.com.mk/lajmi/2790
With this code I can change the link to /lajmi/2790 but i get 404 error.
I mean i get the link
http://www.domain.com.mk/lajmi/2790, but it has 404 error (i dont se the content)
This is my code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com\.mk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com\.mk$
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^lajmi\.php$ http://domain.com.mk/lajmi/%1? [R=302,L]
What I am doing wrong ?
Try this one :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\.mk$
RewriteCond %{QUERY_STRING} ^id=(\d*)$
RewriteRule ^lajmi\.php$ http://domain.com.mk/lajmi/%1? [R=302,L]
RewriteRule ^lajmi/(\d*)$ lajmi.php?id=$1&r=0 [L]
(the &r=0 in the final rule is for not getting an infinite loop)
Single direction rewrite:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\.mk$
RewriteRule ^lajmi/(\d*)$ lajmi.php?id=$1 [L,QSA]
This means that every uri of kind /lajmi/2790 will be passed to /lajmi.php?id=2790 in a sub-request.
However, in this case, if the user hits /lajmi.php?id=2790 by himself, then this is the url he will see in the browser, not the "beautified one".
Bi-directional rewrite:
RewriteEngine On
RewriteBase /
; Redirect lajmi.php?id=2790 to a beutified version, but only if not in sub-request!
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\.mk$
RewriteCond %{IS_SUBREQ} !=true
RewriteCond %{QUERY_STRING} ^id=(\d*)$
RewriteRule ^lajmi\.php$ lajmi/%1 [R=301,L]
; Make the beutified uri be actually served by lajmi.php
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\.mk$
RewriteRule ^lajmi/(\d*)$ lajmi.php?id=$1 [L]
Here, an additional RewriteCond was added to the first rule checking that this is not a sub-request, to ensure that the rules do not loop.
You can pick which way you like, but the first approach is enough if you build the links in your HTML in the 'beautified' way already (no need to redirect the browser twice just to see the page).
I got the following url:
127.0.0.1/abc_123456/default/index/index/
Which should be rewritten to:
127.0.0.1/123456/index.php/default/index/index/
So remove abc_ and add index.php after it. Problem is that the digits are variable, but the abc_ isn't.
I had the following rule:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /abc_
RewriteRule ^abc_(.*)/(.*)$ /$1/index.php/$2
But that resulted in the url being rewritten to:
127.0.0.1/123456/default/index/index.php/index/
Seems like I'm almost there, but I can't figure it out.
Thanks in advance
Use this simple rule:
RewriteRule ^abc_([0-9]+)/(.*)$ $1/index.php/$2 [L,NC]
Try
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /abc_([0-9]+)/([^\ \?]+) [NC]
RewriteRule ^ /%1/index.php/%2 [L]
EDIT
However, you are right about the other rule, that's the one giving the error; RewriteCond %{THE_REQUEST} !^[A-Z]+\ /abc_ RewriteRule ^(.*)$ /index.php/$1 That one is used to rewrite if the page does not contain the /abc_123456/
Add an extra condition to that rule as below
#if not abc_
RewriteCond %{THE_REQUEST} !^[A-Z]+\ /abc_ [NC]
#if not already index.php
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
for example, if you need similar solution, when visited this url:
http://yoursite.com/subpage1/subpage2/?YOURSTRING=blabla
to redirected visitor to
http://yoursite.com/subpage1/subpage2/
then see link - http://stackoverflow.com/a/15680832/2215124
So, I am trying to make: sub.example.com/page rewrite to www.example.com/sub/page
I have this code which does work (note last character):
RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).example.com [NC]
RewriteRule ^(.*) http://www.example.com/%1/$1 [R]
And this code that does not:
RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).example.com [NC]
RewriteRule ^(.*) http://www.example.com/%1/$1 [L]
I want the url to remain as the user typed it in, but this seems to produce a 500 error. I've enabled logging to try to assist, but it doesn't provide any clues. Is this possible?
Try changing the last Rule to
RewriteRule ^(.*) http://www.example.com/%1/$1 [P]
If you list your directory structure to show how sub.example.com and www.example.com are related, this may also be possible via a rewrite vs the more expensive (slower) proxy solution above.
I know I am missing something simple, but I can't get this redirect to work right. I have a parked domain that I want to redirect to the main domain. I am using:
RewriteCond %{HTTP_HOST} ^parked-domain.com$ [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/$1 [L,R=301]
The problem is that parked-domain.com/anypage.html redirects to main-domain.com and leaves off the rest of the URL. I need parked-domain.com/anypage.html to redirect to main-domain.com/anypage.html
EDIT
I am sure this is a cache thing with my browser but after I tried the first suggestion then changed it back, now I get this:
parked-domain.com/anypage.html redirects to www.main-domain.com/anypage.html
but
www.parked-domain.com/anypage.html does not redirect at all.
Part of the problem was with the cache, that got part of the redirect working. I ended up using this to get it all forwarding properly:
RewriteCond %{HTTP_HOST} ^parked-domain.com$ [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.parked-domain.com$ [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/$1 [L,R=301]
The first one should have worked for all cases, but it didn't. Adding the second redirect fixed it.
Try removing the ^ $ around your (.*)
RewriteRule (.*) http://www.main-domain.com/$1 [L,R=301]