I have an htaccess code block that works fine well except under one particular condition:
One, I add a 'www' when there isn't one, that works.
Two I chop off 'index.html' when that appears.
The problem occurs, when I have NO 'www' AND "index.html' on the end.
I get the www added and then the index is chopped off and a whole URL string is added
thereby duplicating my URL and causing a 404.
http://www.example.com/http://www.example.com
Here is my block whats wrong?
RewriteCond %{HTTP_HOST} !^www\.kisswedding\.com$ [NC]
RewriteRule ^(.*)$ http://www.kisswedding.com/$1 [L,R=301]
#RewriteCond %{REQUEST_URI} /index\.html?$ [NC]
#RewriteRule ^(.*)index\.html?$ "/$1" [NC,R=301,NE]
I am sure its just a simple thing but I am too dang tired to see it so I ask you guys :)
L
I think you need to add the L flag, so that Apache will be told to stop rewriting in that rule
RewriteCond %{HTTP_HOST} !^www\.kisswedding\.com$ [NC]
RewriteRule ^(.*)$ http://www.kisswedding.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} /index\.html?$ [L,NC]
RewriteRule ^(.*)index\.html?$ "/$1" [L,NC,R=301,NE]
Related
Today I have
https://www.teste.com/app/assets/folderX/file.pdf
But I need to redirect to:
https://assets.teste.com/folderX/file.pdf
I got close to the solution with:
RewriteCond %{REQUEST_URI} ^/app/assets/ [NC]
RewriteRule ^(.*)$ https://assets.teste.com/$1 [R=301,L,QSA,NC]
But the rewrite ended like:
https://assets.teste.com/app/assets/folderX/file.pdf
On the ReWrite I need to remove the subfolder /app/assets/ from it.... but I have no idea how.
After some tries. could do it using:
RewriteCond %{REQUEST_URI} ^/app/assets/ [NC]
RewriteRule ^/?app/assets/(.*)$ https://assets.teste.com/$1 [R=301,L]
I nice tool to test is https://htaccess.madewithlove.be/
You may use this rule instead:
RewriteCond %{HTTP_HOST} ^(?:www\.)?(teste\.com)$ [NC]
RewriteRule ^(app)/assets/(.*)$ https://$1.%1/$2 [R=301,L,NE,NC]
Make sure to use a new browser to test this change or completely clear old browser cache.
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]
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
I have a bunch of .htaccess rules that follow this format
RewriteCond %{HTTP_HOST} ^www.lazygamer\.co.za$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]
Now I need to put in a new rule to include a category string in my URL and was given this code
RewriteRule ^/([^/]+)/$ /category/$1/ [R]
But it's not being fired for some reason, can someone please show me how to change the above string to match the rule further up.. so I check for some condition before executing the rule?
I only need this rule to fire if the url is in the format http://www.lazygamer.net/post-name/ and not when the url is in the format http://www.lazygamer.net/category/post-name/
RewriteCond %{REQUEST_URI} !^/category/.*$
RewriteRule ^([^/]+)/ /category/$1/ [R]
My htaccess file now looks like this and solves the problem
RewriteCond %{HTTP_HOST} !^images.lazygamer\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-content|wp-admin|wp-includes|fixed|contact-details|advertise|about|category|submission|images|ps3|xbox-360|wii|other-news|video).*$
RewriteCond %{REQUEST_URI} !^\/$
RewriteRule ^(.*)$ http://www.lazygamer.net/fixed/$1 [R=301,L]
The second last line ignore the root folder which kept me up all night...
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]