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]
Related
I want to redirect my file in folder A to folder B with the same file name.
EG.
yourdomain.com/folderA/nosedigger.php
to
yourdomain.com/folderB/nosedigger.php
The .htaccess is at yourdomain.com/folderA/.htaccess.
I tried the following but it does not work like a charm. Need help. Totally have no clue what the codes in .htaccess really mean.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/folderB/ [NC]
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^ /folderB/$2 [R=301,L]
To redirect from foldera to folderb, you can use the following redirect above your other rules
RedirectMatch ^/foldera/(.*)$ /folderb/$1
this should be all you need:
RewriteEngine On
RewriteRule /folderA/(.*) /folderB/$1 [R=302,NC]
maybe:
RewriteRule ^folderA(/.*)?$ folderB$1 [R=302,NC]
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]
Target is to create friendly URL, and I got stuck here.
My link below:
Turpināt lasīt..
My .htaccess
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^blog/([0-9]+)/?$ blog.php?id=$1
No problems in configuration, simple rewrite rules work. What's wrong here?
Thanks
Ok try this code:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+blog\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /blog/%1? [R=301,L]
RewriteRule ^blog/([0-9]+)/?$ /blog.php?id=$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]
Currently I working through my localhost in MAMP. I have read and research for the proper way to allow .htaccess file url rewrite and was successful. But now, the file is not formatting the links at all as desired. For example I have three pages index.php, about.php and contact. I am using MVC for the frame working of my site. Is this a problem with the code in the .htaccess file or my localserver?
Currently links look like this when going from one page to another:
localhost/mvc/index.php?
localhost/mvc/index.php?p=about
localhost/mvc/index.php?p=contact
.htaccess should format the links to look like this:
localhost/mvc/index/?
localhost/mvc/about/?
localhost/mvc/contact/?
.htaccess:
<IfModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Set the base to this directory:
RewriteBase /mvc/
# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
</IfModule>
Replace your existing .htaccess code fully with this code:
Options +FollowSymLinks -MultiViews
DirectoryIndex index.php index.html
# Turn mod_rewrite on
RewriteEngine On
# Set the base to this directory:
RewriteBase /mvc/
# Redirect /mvc/index.php?p=page to /mvc/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+mvc/index\.php\?p=([^\s]+) [NC]
RewriteRule ^ %1/? [R=302,L]
# Redirect /mvc/index.php to /mvc/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+mvc/index\.php\s [NC]
RewriteRule ^ /mvc/ [R=302,L]
# Internally forward certain /mvc/page/ to /mvc/index.php?p=page
RewriteRule ^(about|contact|this|that|search)/?$ /mvc/index.php?p=$1 [L,QSA,NC]
Replace
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
with :
RewriteRule ^(about|contact|this|that|search)/\?$ index.php?p=$1
I just escaped the ? with a slash because, otherwise, you don't do this, the question mark will be interpreted and will means that the slash before it is optinal.