I have a problem with .htaccess redirect:
in my site, I already have a file htaccess with this strings:
RewriteEngine On
RewriteRule ([^/\.]+)/page/?$ cms.php?lang=$1&livello1=page [L,QSA]
and I want to do redirect from "http://example.com/it/page" to "http://newexample.com/negozio/page1".
My code for redirect is:
#REDIRECT
Redirect /it/page http://newexample.com/negozio/page1
When I try to do this, the redirect becomes
http://newexample.com/negozio/page1?lang=it&livello1=page.
How can I delete "?lang=it&livello1=page"?
Does "?lang=it&livello1=page" originate from my .htaccess?
Sorry,
but I found no solutions on google.
Thank's.
Add a ? at the end of the redirect:
#REDIRECT
Redirect /it/page http://newexample.com/negozio/page1?
Related
I would like to 301 redirect my old domain say m.oldwebsite.com to m.newwebsite.com.
I believe the line below will redirect and keep the url path.
RewriteRule ^(.*)$ https://m.newwebsite.com/$1 [L,R=301]
What I need is for all links on m.oldwebsite.com to redirect to the home page of m.newwebsite.com.
Forexample:
m.oldwebsite.com/path/to
to redirect to
m.oldwebsite.com
I couldn't find a clear solution for this.
Thanks!
Remove $1 parameter from rewrite and it's done, all redirect to homepage.
I'm trying to redirect camping.website.com to website.com/camping. I have an .htaccess file under the subdomain on my server with this rule:
Redirect 301 / https://website.com/camping/
With the slash on the end like above, the URL it returns is:
https://website.com/camping/camping/camping/camping/camping/camping/camping/
If I remove the slash on the end, it will return this instead:
https://website.com/campingcamping
If I change the destination URL to anything else, the redirect works normally. It's only when I have the word "camping" that it messes up. Is there some kind of conflict because the folder I'm trying to redirect to is the same as the subdomain?
Edit: I should mention something else. The following redirect:
Redirect 301 /category/camping-parks/ https://website.com/camping/camping-parks/
Returns this:
https://website.com/campingcamping/camping-parks/
Strange, huh?
Your problem is within this rule :
Redirect 301 / https://website.com/camping/
Will catch both domain and subdomain requests as you commented that they are in same server.
Try this using mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?camping\.website\.com [NC]
RewriteRule ^(.*)$ https://website.com/camping/$1 [L,R=301]
Note: clear browser cache then test
I am having trouble redirecting an entire directory that no longer exists on our server.
All variations of the following are not working and I simply get a 404 Page Not Found.
.htaccess file looks like this:
redirect 301 /non_existent_directory/ http://my.website.com/existent_directory/
Is it possible to use the Redirect 301 directive for this? Or is this only solvable by mod_rewrite?
Thanks
I even tried:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?my\.website\.com\/non_existent_directory\/$ [NC]
RewriteRule ^(.*)$ http://my.website.com/existent_directory/ [R=301,L]
No luck...
From the Redirect documentation, I would say
Redirect 301 /non_existent_directory http://my.website.com/existent_directory
or
Redirect 301 /non_existent_directory /existent_directory
should work, provided you are allowed to use this in a .htaccess file. See also Troubleshooting .htaccess files. You should test without 301 though, to prevent caching of bad redirects by the client.
If this doesn't work, you can try a RewriteRule of course
RewriteEngine On
RewriteRule ^/?non_existent_directory(.*)$ /existent_directory$1 [R,L]
But this is equivalent to the above Redirect directive.
I have a URL structure of:
mysite.com/user/(someusername)
and want to redirect only the base URL which is:
mysite.com/user/
to
mysite.com/users/ or mysite.com/members/
But the problem is when i add this line to htaccess.
redirect 301 /user /users/
Even
mysite.com/user/(someusername)
gets redirected to
mysite.com/users/(someusername)
How can i redirect /user/ only?
Thanks!
RewriteEngine on
RewriteBase /
RewriteRule ^user/$ users/ [L,R]
I did some htaccess URL rewrite. To keep my google ranking I must redirect the old URL to the new one; the problem is the old URL still 'exist' and I'm not sure how to do the redirect. This is an example:
old url: mypage.php?id=myId
which now is rewritten as: mypage-myId.html
this is the htaccess directive
RewriteRule ^mypage-([A-Za-z0-9_-]+).html$ mypage.php?id=$1 [L]
now I want to 301 redirect all the old url (mypage.php?id=myIds) to the new url (mypage-myIds.html).
I tried this at the top of my htaccess file:
redirect 301 mypage.php?id=1 to mypage-1.html
but nothing happens, the page stays on mypage.php?id=1.
What's wrong with this? I found another post about this problem
url rewrite & redirect question
but the solution wasn't that clear to me.
Thanks in advance
Vittorio
You could try this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([A-Za-z0-9_-]+)$ # fetch ID
RewriteRule ^mypage\.php$ http://domain.com/mypage-%1.html [R=301,L] # redirect old URL to new
RewriteRule ^mypage-([A-Za-z0-9_-]+)\.html$ mypage.php?id=$1 [L] # rewrite