htaccess redirect puts old path in parameter - .htaccess

I want to forward one specific URL to another one. Tried this:
Redirect 301 "/stellenangebote-berlin" "http://mydomain.de/stellenangebote-in/berlin"
The forward works, but the old URL is appended as parameter like so:
www.newURL/deeplink.php?path=stellenangebote-berlin
This breaks my further routing. How can I prevent the script from adding the old path?
Thanks!

Did you try like below because I'm using the below way in my server and it's working fine.
RewriteCond %{HTTP_HOST} ^OLDDOMAIN\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.de/stellenangebote-in/berlin [R=301,L]
Or you can try it in one more way like below.This one redirects everything after the domain name on the url to the exact same copy on the new domain url:
RewriteEngine on
RewriteRule ^(.*)$ http://mydomain.de/stellenangebote-in/berlin$1 [R=301,L]

Related

Redirect index.php with parameters to a folder and remove parameters using htaccess

I have searched but cannot find a specific answer for this exact redirect style...
I have this structure of URL with this specific parameter:
https://websitename.com/directory/index.php?option=com_virtuemart&view=cart
I want it redirected to:
https://websitename.com/shopping-cart/
Note that the above mentioned "directory" changes, but the index.php with the parameters stay the same. No matter what the directory is, I always want it to go to the same exact redirect.
I cannot seem to get the right redirect working in htaccess. Can anyone help?
You can use this redirect rule as your first rule in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?option=com_virtuemart&view=cart [NC]
RewriteRule ^ /shopping-cart/? [L,R=308]
# remaining rules go below this
You can use a set like this. It takes care on the param view=cart
RewriteCond %{QUERY_STRING} (^|&)view=cart
RewriteRule ^(.*)$ /shopping-cart/? [L,NC,R=301]
If you want to keep the querystring params, then change
/shopping-cart/?
to
/shopping-cart/
without questionmark

.htaccess redirect folder to subdomain

I've tried applying a few of the answers found on stackoverflow, but either I'm missing something or I'm plain dumb.
Basically I got a main domain name. This domain already has a non-www redirect. So http://domain.com becomes http://www.domain.com. This domain also has a mobile version found inside the the 'm' folder. So accessing the domain name like http://www.domain.com/m/ works and so does http://m.domain.com. What I'm trying to achieve is simple: anyone whom goes to the site via http://www.domain.com/m/, or http://www.domain.com/m/about should be redirected to the subdomain version so to http://m.domain.com or http://m.domain.com/about in the second case listed above.
Whatever I tried implementing ended up with errors, either I managed to disable direct access to m.domain.com, but it worked via domain.com/m/, or redirect loops.
Thanks!
You can use this code in your DOCUMENT_ROOT/.htaccess file of domain.com main .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^m/(.*)$ http://m.%1/$1 [L,NC,R=302]
# non-www to www
RewriteCond %{HTTP_HOST} !^(m|www)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,NC,R=302]

Can I use htaccess to redirect requests to the domain name to a subdirectory

I have changed the A record for domainname.com to point to the IP address of subdomain.domainname.com. That's working.
Now, I'd like to change the htaccess so that any requests made to domainname.com are redirected to subdomain.domainname.com/subdirectory
Is this possible? And if so, what's the command please?
You'd be better off using Name based Virtual hosts, but if you want to use a .htaccess file something along the following lines will do the trick:
RewriteCond %{HTTP_HOST} ^domainname.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdirectory
RewriteRule .* /subdirectory%{REQUEST_URI} [L]

htaccess to add directory after domain name?

How can I use htaccess to always ADD a directory immediately after the domain name?
So for example, change requests for
http://domain.com/path-to/file.php
to
http://domain.com/added-directory/path-to/file.php
The context here is that i am migrating a site to a new server, and the domain name is not yet pointed to the new server. But the hosting company provides me with a "temporary url" based on the Shared IP and my account username, so http://216.172.172.211/~myusername/ , but all the paths in all the html are doc-root relative, like /images/logo.png, which translates to http://216.172.172.211/images/logo.png which is wrong. I need it to be http://216.172.172.211/~myusername/images/logo.png .
try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/~myusername
RewriteRule ^(.*)$ /~myusername/$1 [L]
If you want to redirect so that URLs show the ~myusername part in the URL address bar, add an R flag to the square brackets:
RewriteRule ^(.*)$ /~myusername/$1 [L,R=301]
This worked for me perfectly
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/~gye
RewriteRule ^(.*)$ https://%{HTTP_HOST}/gye/$1 [R=301,L]
If an URL comes without the /XYZ
Add https:// at the beginning and /gye/ after the domain.
Testing here really helped: https://htaccess.madewithlove.be/

htaccess redirects from URLs on one domain to the root of another domain

Currently what is happening is people are accessing old URLs from google like icpaweb.com/site/pages/about-us/ and being sent to their corresponding urls on icpaweb.org : icpaweb.org/site/pages/about-us.
What I want is to send people from: icpaweb.com/site/pages/about-us to icpaweb.org/ without any of the succeeding url segments.
How do I do this?
If you have to use an .htaccess file, you can use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} icpaweb.com$ [NC]
RewriteRule .* http://icpaweb.org/ [R=301,L]
That will 301 redirect all requests for icpaweb.com to the index root of icpaweb.org. If you don't want 301, it can just be R.
You'll need to replace or turn off whatever mechanism is doing your redirecting now, they may not be compatible.
Use an url rewrite rule.
2 steps:
Write a RewriteCond so that the following rewrite rule only apply for url with host being icpaweb.com like RewriteCond %{HTTP_HOST} icpaweb.com$ [NC] The [NC] is for case insensitive match
Write a rewrite rule that convert all input to what you want like RewriteRule ^.*$ http://icpaweb.org/ [L]The [L] is to stop the rewriting to this rule if rule executed.

Resources