I saw many 301 questions but I haven't found a solution for mine so I'll just post it here.
The standard 301 looks something like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.301redirect\.de$
RewriteRule ^(.*)$ http://www.301redirect.de/$1 [L,R=301]
Well, when I surf to my website I end up on www.domain.tld/index.php/restofquery. I want to get to www.domain.tld/ when I surf to domain.tld and I also want no index.php in any other query. So domain.tld/articlebla should be www.domain.tld/articlebla.
Any way to accomplish this?
Best regards.
To simply add on the www you would do:
RewriteCond %{http_host} ^301redirect\.de$ [NC]
RewriteRule ^/?$ http://www.301redirect.de/ [R=301,NC]
To also add on the other urls parts and www, you would do:
RewriteCond %{http_host} ^301redirect\.de$ [NC]
RewriteRule ^(.*?)/?$ http://www.301redirect.de/$1/ [R=301,NC]
If you mean you don't want the original query string on the redirect url then this will work:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.301redirect\.de$
RewriteRule ^(.*)$ http://www.301redirect.de/$1/? [L,R=301]
Adding a ? to the end of the RewriteRule means that the query string won't get added.
Related
Trying to get
www.example.com
to go directly to
www.example.com/forum
How can I do this with this configuration? Thanks in advance.
Edit:
Right now I have added below content in .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteRule ^(.*)$ /forum/$1 [L,R=301]
I want result like
https://www.example.com/topic/topic-url/
to
https://www.example.com/forum/topic/topic-url/
With your shown samples, could you please try following. Please clear your browser cache before testing your URLs. Your tried rules will be creating an infinite loop hence it may not be working, I have added a condition if uri doesn't start from forum then only proceed with redirection.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{REQUEST_URI} !^/forum [NC]
RewriteRule ^(.*)$ /forum/$1 [L,R=301]
I'm trying to redirect http://vacation.website.com/category/spa-vacations/ to http://website.com/vacations/spa-vacations/
RewriteEngine On
RewriteRule ^category/(.*)$ $1
RewriteCond %{HTTP_HOST} ^vacation\.website\.com [NC]
RewriteRule ^(.*) https://website.com/vacations/$1 [L,R=301]
With this htaccess, the first rule seems to be applied and removes "category" from the URL - then it's like it never happened and I'm left with http://website.com/vacations/category/spa-vacations/
Why doesn't the first change to the URL stick and is it possible to make it do so?
To redirect
http://vacation.website.com/category/spa-vacations/
to
http://website.com/vacations/spa-vacations/
Try this :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?vacation\.website\.com [NC]
RewriteRule ^category/(.*)$ https://website.com/vacations/$1 [L,R=301]
Note: clear browser cache then test.
I have multiple domains directed to folder with .htaccess
my htaccess looks like this:
RewriteEngine On
rewritecond %{http_host} ^domain-2.com
rewriteRule ^(.*) https://domain-1.com/?utm_source=redirects&utm_medium=domain-2.com&utm_campaign=301 [R=301,L]
rewritecond %{http_host} ^domain-3.com
rewriteRule ^(.*) https://domain-1.com/?utm_source=redirects&utm_medium=domain-3.com&utm_campaign=301 [R=301,L]
And I want do this more effective and elegantly - all domains are redirected to domain-1.com
Exist any way how use {HTTP_HOST} or something similar at URL parameters?
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} !domain-1\.com$ [NC]
RewriteRule ^(.*)$ https://domain-1.com/?utm_source=redirects&utm_medium=%{HTTP_HOST}&utm_campaign=301 [R=301,L]
I have a single site within IIS, which runs on 4 different hostnames. The CMS handles that, and displays the correct site based on the incoming hostname.
I need to use ISAPI rewrite to handle all the old urls and 301 redirect them to the new equivalants, this is how I currently deal with redirects in my ISAPI-rewrite .htaccess file
RewriteEngine on
RewriteRule ^post/my-old-page-one$ /my-newer-page-one [R=301]
RewriteRule ^post/my-old-page-two$ /my-newer-page-two [R=301]
My issue is, I need it to check the domain too for the incoming url. As the sites have the same old urls, which now need to go to a different page.
I was hoping I could so this.
RewriteEngine on
RewriteRule ^http://www.siteone.com/post/my-old-page-one$ http://www.siteone.com/my-newer-page-one [R=301]
RewriteRule ^http://www.siteone.com/post/my-old-page-two$ http://www.siteone.com/my-newer-page-two [R=301]
RewriteRule ^http://www.sitetwo.com/post/my-old-page-one$ http://www.sitetwo.com/my-newer-page-one [R=301]
RewriteRule ^http://www.sitetwo.com/post/my-old-page-two$ http://www.sitetwo.com/my-newer-page-two [R=301]
But it doesn't work. Any advice greatly appreciated.
The check of the hostname is performed in a separate condition, like this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.siteone\.com$ [NC]
RewriteRule ^post/my-old-page-one$ http://www.siteone.com/my-newer-page-one [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^www\.siteone\.com$ [NC]
RewriteRule ^post/my-old-page-two$ http://www.siteone.com/my-newer-page-two [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^www\.sitetwo\.com$ [NC]
RewriteRule ^post/my-old-page-one$ http://www.sitetwo.com/my-newer-page-one [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^www\.sitetwo\.com$ [NC]
RewriteRule ^post/my-old-page-two$ http://www.sitetwo.com/my-newer-page-two [R=301,NC,L]
I'm not sure if this is possible, but here's whats going on.
I currently have an .htaccess rule to redirect example.com to store.example.com
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://store.example.com/[L,R=301]
This works great, however my search queries no longer work. What I'd like to do is redirect example.com to store.example.com unless I'm searching.
A sample search would look like this:
http://example.com/?s=my+search+query+string
Thank you in advanced for your help
Have you tried:
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{QUERY_STRING} ^!(s=(.*))$
Rewriterule ^(.*)$ http://store.example.com/ [L,R=301]