301 Permanent Redirect, Redirecting Incorrectly? - redirect

I'm trying to redirect traffic that attempts to access:
cat.rs.allgames.com/cloud/11/services/titles/game5/console/file.json
to:
cat.cloud.allgames.com/titles/game5/console/file.json
using a 301 permanent redirect in an .htaccess file, but it always sends me to:
cat.cloud.allgames.comcloud/titles/game5/console/cloud/11/services/titles/game5/console/file.json
which is nowhere near correct. What am I doing wrong?
My .htaccess is located in:
cat.rs.allgames.com/cloud/11/services/titles/game5/console/file.json
and looks like this:
Redirect 301 / http://cat.cloud.allgames.com

The Rewrite module should do what you want! You need to make sure the rewrite module is enabled (for ubuntu: sudo a2enmod rewrite), then add this to your .htaccess file.
RewriteEngine On
RewriteRule ^/cloud/11/services/titles/(.*)$ http://cat.cloud.allgames.com/titles/$1 [R=301]
Here, the ^/cloud/11/services/titles/(.*)$ catches anything after the titles part of the URL. Then the $1 at the end of the second part attaches what we caught to the end of the new URL. Finally, you can specify it as an external 301 rewrite to another server with the [R=301] flag!
Hope that works for you!

Related

301 redirect htaccess and Nginx settings issues and .composer folder

I've had some hit and miss results setting up htaccess to forward on a couple of aged domains I acquired to my main site. I wouldn't describe myself as advanced more an enthusiastic intermediate so a nudge in the right direction would be greatly appreciated. I've checked answers but nothing definitive that I can see that relates to my specific issue and the composer folder. In Apache/Nginx I have in directives (http/https)
RewriteEngine On
ErrorDocument 404 https://my-main-site.com/my-page-or-blog-post/
I have 'Restrict the ability to follow symbolic links' unchecked as I have reference to symlinks in htaccess and so avoids a 500 error. I also have put up a static html page so if anyone hits the old aged domain it's not an automatic redirect they'll see the static HTML page with reference to the old/aged domain. So the 301 is sort of in the background but I'm getting a 302 result. My htaccess looks like this......
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^old-site-aged-domain.com$ [NC]
RewriteRule ^(.*)$ https://my-main-site.com/my-page-or-blog-post/ [R=301,L]
However when I go in to AHREFS and look at the backlink data it's showing a 302, however it does confirm http>https is working fine.
http://www.old-site-aged-domain.com/info-page.html
301
https://www.old-site-aged-domain.com/info-page.html
302
https://my-main-site.com/my-page-or-blog-post/
In my site root I also have .composer folder (as well as error_docs, .ssh, httpdocs, logs, .revisium_antivirus_cache), I'm sort of aware what the purpose of this is (PHP) but there are 2 further htaccess files in there, the second smaller htaccess file only has 'deny from all' as content. I wonder if this folder with these 2 htaccess files is presenting a problem/conflict i.e. 3 x htaccess files. The smaller htaccess file is in .composer/cache. The larger htaccess file is in .composer. Should I delete these 2 x htaccess files in .composer folder.
Thanks in advance for any help
James
rewrote htaccess on numerous occasions but without success

Apache config issue

So I'm experiencing the following issue :
If I add this line in in my site.conf file it doesn't work:
RewriteEngine On
Redirect 301 /contact-us /contact
Redirect https://www.website1.com/ https://www.website2.com/
I've added it in the , is this wrong or should I add it in a different line.
Thanks.
Figured it out, add this in <virtualhost *:80>
Redirect permanent /contact-us /contact
Redirect permanent /motorists/products /products
Redirect permanent /about/directorate /about
Restart apache and test.

PrestaShop: non-www URLs redirecting to 404 error page

I am experiencing a weird issue on my PrestaShop website.
When I am opening an URL without WWW on it, it redirects to the WWW page, but displays 404 page.
for example, when I am trying to access http://mydomain.com/home/contact-us it takes me to http://www.mydomain.com/home/contact-us?controller=404. It should not add ?controller=404 to the end of the url. Why it's doing this and how to fix this issue?
You need to manually edit the .htaccess file of your Prestashop website. You can redirect all non-www urls to add www using this code.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Place the code on top of your .htaccess file or within the condition block for checking mod_rewrite
you can set your url under "Preferences > SEO & URLs". you have to change the options "Shop domain" and "SSL domain" there you can set with or without "WWW".
This is most probably cased by not-generated .htaccess file. Go to BackOffice -> Preferences -> SEO & URLs and click [Save]. This will regenerate your .htaccess file.

Cannot get 301 redirect to work in .htacess

I have been looking through the various threads related to .htacess 301 redirects and I simply cannot find a solution to my problem. I have added this into the .htaccess which was previously an empty file...
redirect 301 http://www.architekogp.com/index.html http://www.owenprescott.com/index.php
The .htaccess is located in the architekogp.com root folder (public_html/.htaccess). I am not sure if the .html to .php is causing the issue? Thanks in advance for any advice.
Wait so all all your code in .htaccess is:
redirect 301 http://www.architekogp.com/index.html http://www.owenprescott.com/index.php
Correct?

.htaccess file disappears in filezilla? how to check if file is present or not?

for some weird reason my CMS is logging out if the address bar does not have www before the full website name. for example, when we enter xyz.com, it takes me to the website but then it wont show as logged in and if i type in www.xyz.com it will find the cookie and show me logged in.
What i want to do is, when user types in xyz.com, i want it to directly (transparent to user) go to www.xyz.com. I want to add that www before xyz.com. I tried adding a .htaccess file in the directory where index.php is present and this is code in htaccess file.
DirectoryIndex index.php
Redirect xyz.com www.xyz.com/index.php
The .htaccess file is disappearing when i transfer it over ftp filezilla.
If you are willing to modify your index.php you could add the following logic to the top of the file:
/*This is a tempory redirection from mysite.com to www.mysite.com*/
if($_SERVER['SERVER_NAME'] == 'mysite.com')
{
$redirect = $_SERVER['REQUEST_URI'];
header( 'Location: http://www.mysite.com'. $redirect ) ;
}
try this in the htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^/?$ "http://www.xyz.com" [R=301,L]
However, your problem sounds like cookie related. Probably the CMS is using a cookie to check the log in status, but the cookie domain param is 'www.xyz.com' instead of '.xyz.com'.
--- edit ---
improved a bit the final line of the code (it is tested and working), but as tcp said, mod_rewrite must be enabled. If you can't enable it, try the code that Lobsterm posted and if you can't do this either, you could try to change the cookie domain param from 'www.xyz.com' to '.xyz.com'
If you want to use rewrites, make sure mod_rewrite is being loaded in your Apache conf file and check that the AllowOverride parameter is either set to All or the just the directives you want to be allowed in .htaccess
Also as aletzo said, you probably want your cookie to cover your whole domain so change the cookie domain from www.example.com to example.com .
Then, it won't matter if user are accessing with a www prefix or within a subdomain.
EDIT: Glad you found the answer you were looking for, but if you need to make filezilla show you .htaccess in the future, Server -> Force showing hidden files