How do I redirect a link to a particular link using .htaccess
http://www.example.com/one http://differentdomain.co.uk/a/
http://www.example.com/two http://differentdomain.co.uk/b/
http://www.example.com/three http://differentdomain.co.uk/c/
http://www.example.com/four http://differentdomain.co.uk/d/
i have tried Redirect 301 & RewriteRule but its not working at all, im using an apache server
This is what i have on my .htaccess file
<IfModule mod_rewrite.c>
#Options +FollowSymLinks
#Options +Indexes
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^/one http://differentdomain.co.uk/a/ [R=301,L]
</IfModule>
both these codes dont work for me
Redirect 301 /one/ http://differentdomain.co.uk/a/
RewriteRule ^/one http://differentdomain.co.uk/a/ [R=301,L]
by the way the domain I'm working on is empty only the .htaccess & cgi-bin folder is present
I think (not sure) Redirect directive doesn't work because you don't have /one path in your root.
try this :
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^one http://differentdomain.co.uk/a/ [R=301,L]
Related
I like to redirect all pages under olddomain.com/subdirectory/ to be redirected to newdomain.com?
The newdomain.com site has a new URL structure, so I want every page under the olddomain.com/subdirectory/urls to be redirected to the newdomain.com homepage.
I tried below code.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^olddomain.com/subdirectory/$ [NC]
RewriteRule ^(.*)$ http://newdomain.com [R=301,L]
</IfModule>
But its redirecting with existing url like http://newdomain.com//url and its through 404 error.
Any help highly appreciated. Thanks
You can use the following rule :
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^subdir/(.*)$ http://newdomain.com/ [R=301,L]
</IfModule>
I have problem using .htaccess to rewrite some of the friendly URL.
The root URL is http://www.example.com/my/
The working call url is http://www.example.com/my/Post.php?id=2
Both .htaccess file and Post.php are located in the sub-directory http://www.example.com/my/
But I wanted it to be like the following:
http://www.example.com/my/job/kuantan/?id=2
The .htaccess configuration as below:
DirectoryIndex index.php
Options All -Indexes
#ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^job/kuantan/([0-9]+) /Post.php?id=$1 [L,QSA, NC]
BUT, once i deployed the above .htaccess configuration file, it prompted 500 internal error message as well.
Is something missing or wrong in the .htaccess configuration? Please advice and really appreciated if someone there could give a hand. Thanks.
You should just need a single rule:
RewriteRule ^/my/job/kuantan/$ /my/Post.php
The query string is carried over by default.
Assuming that .htaccess and Post.php are located in the sub-directory /my/:
DirectoryIndex index.php
Options All -Indexes
#ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^job/kuantan/([0-9]+)$ Post.php?id=$1 [L,QSA,NC]
Remove all spaces between []. Change /Post.php?id=1 to Post.php?id=$1.
You can have this code in /my/.htaccess:
DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /my/
RewriteCond %{THE_REQUEST} /Post\.php [NC]
RewriteRule ^ job/kuantan [R=302,L,NE]
RewriteRule ^job/kuantan/?$ Post.php [L,NC]
Query String is automatically carried over so there is no need to capture it in rule.
I had a paid domain, I did put a folder with the name of the domain (mysite.net) in the server
I don't want to pay for the domain anymore, so I want to use the default subdomain given by my hosting service (mysitenet.ipage.com) but the problem is what I said above, it exists a folder with the name of my paid domain, like this:
/
/mysite.net
/cgi.bin
I read this solution to try redirection:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/mysite.net[NC]
RewriteRule ^ /mysite.net%{REQUEST_URI} [R=301,L]
with this rules I go to mysitenet.ipage.com and redirects me to mysitenet.ipage.com/mysite.net as I want, but is there a way to hide the 'mysite.net' part?
You can put this code in your htaccess (which has to be in root folder)
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(?!mysite\.net/)(.*)$ mysite.net/$1 [L,QSA]
EDIT: if you want to avoid duplicate content and also redirect /mysite.net/something to /something
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/mysite\.net/([^\?\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteRule ^(.*)$ mysite.net/$1 [L,QSA]
I'm attempting to perform a simple 301 redirect via htaccess, the redirect works but adds "?folder=X" to the URL.
For instance:
Redirect 301 /pets http://www.mydomain.com/discount-pet-products
Returns:
http://www.mydomain.com/discount-pet-products?folder=pets
How do I remove this?
Here is my htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
Redirect 301 /pets http://www.mydomain.com/discount-pet-products
RewriteRule ^([0-9a-zA-Z-]+)$ load.php?folder=$1 [L]
Try this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^/pets$ http://www.mydomain.com/discount-pet-products? [R=301,L]
RewriteRule ^([0-9a-zA-Z-]+)$ load.php?folder=$1 [L]
Try this code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^pets/$ /discount-pet-products? [R=301,L]
RewriteRule ^([0-9a-zA-Z-]+)/?$ load.php?folder=$1 [L,QSA]
Make sure to test this in a new browser to avoid browser caching issues.
The answer was placing redirect at top of .htaccess file, before anything
RewriteRule ^pets$ http://www.mydomain.co.uk/discount-pet-products [R=301,L]
I'm stuck with an htacces project. On my old domain i've:
olddomain.eu/en/[uris]
olddomain.eu/de/[uris]
Now i need to split the sites to different domains without losing the indexing so i created this htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^de(.*)$ http://www.domain.de/$1 [L,R=301]
RewriteRule ^en(.*)$ http://www.domain.eu/$1 [L,R=301]
</IfModule>
The only problem is it now redirect like this:
olddomain.eu/de/test.html to www.domein.de instead of www.domein.de/test.html
What am i doing wrong?
Looks close but for correctness you can try this regex:
RewriteEngine On
RewriteRule ^de/(.*)$ http://www.domain.de/$1 [L,R=301,NC]
RewriteRule ^en/(.*)$ http://www.domain.eu/$1 [L,R=301,NC]