IIS URL Rewrite Redirect Rule - iis-7

I have one website with dynamic syntax
url: test.company.com/ssp/...
I would like to redirect to https
http://test.company.com/ssp/test > https://test.company.com/ssp/test
So far i have build one URL Rewrite
Pattern: (.*)
Condition: {HTTPS} / ^OFF$
Action: https://{HTTP_HOST}/{R:1}
i only can redirect to https://test.company.com/ssp
so my ssp/test string is missing
I already tried https://{HTTP_HOST}/ssp/{R:1}.
Can someone explain what i'm missing

Related

Trying to redirect old URL is closest new url using 301 redirectmatch

Please, this is giving me a headache!
I redirected an old site (goo.gl/onQ3UM) to a new directory.
I had all URLs from the old site redirect to the new homepage (which I now realise was a mistake as I got lots of 404's and soft 404's at the start of last week).
So I'm now trying to redirect each page individually to the closest matching page using a 301 redirect.
I changed the htaccess file to read:
Redirect 301 /wp/new-homepage-feb162 /wp/home [(seems to work fine)]
RedirectMatch 301 /mjs/weddings/(.*) /wp/home/grand-country-house-weddings-and-receptions-dorset/
When I perform a 'Fetch' in GSC goo.gl/onQ3UM/mjs/weddings/217-a-testimonial.html?7bffea3334ebaaaf8a005d78b5e86b8e= 300b60a21ae5159ab1e8cf12b7634b7b
It shows as redirecting to /wp/home/grand-country-house-weddings-and-receptions-dorset/?7bffea3334ebaaaf8a005d78b5e86b8e= 300b60a21ae5159ab1e8cf12b7634b7b
Which is almost right but I don't want the ?7bffea3334ebaaaf8a005d78b5e86b8e=300b60a21ae5159a b1e8cf12b7634b7b
How do I get rid of it??!!!
The way you've written this is very confusing... but from my understanding is you're trying to make your URL look 'prettier' after it has been re-directed?
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#To go from URL /example/example1/example2/example3
#To go to URL /example3
RewriteRule ^/example/example1/example2(/.+)$ /$1 [R=302,L,NC]
So the above would turn:
www.example.com/example/example1/example2/example3
Into:
www.example.com/example3

Nginx: redirect regardless of the url structure

I recently moved a subdomain to my main domain but I also changed the url structure.
Previously I had pages like http://sub.domain.com/companies/my-company-id/year/2012/charts
When moving to the main domain, I removed all the complicated urls to juts get:
http://www.domain.com/companies/my-company
I currently have the following rule:
rewrite ^/companies/(.*)$ http://www.domain.com/companies/$1 permanent; but when someone go on a page like http://sub.domain.com/companies/my-company/2012/charts they get redirect to http://www,.domain.com/companies/my-company/2012/charts and get a 404.
I like to force a redirection to http://www,.domain.com/companies/my-company-id regardless of what's after the my-company-id
Currently the parameter $1 is having the entire URI after /companies, so you are getting redirected to the original path. You should only extract the company-id in $1.
Use this:
rewrite ^/companies/(.*)/(.*)$ http://www.domain.com/companies/$1 permanent;
Here the rest of the URI after company-id will be available in the parameter $2, which is not needed in the rewrite condition.

Simple iis rewrite doesn't work

This is what I'm doing in iis manager:
iis - url rewrite -> Add rule ->
Action type: rewrite
Pattern: MySite.com (Exact match)
Rewrite url: MySite.com/Folder1/Default.aspx
So how do I return the Default.aspx page while maintaining the MySite.com in the address bar?
OK. So I found the answer:
Only the part after the domain name and trailing slash should be entered.

needed a suggestion in redirecting old URLs to a new URL

Earlier i have installed my code in the main domain itself. for instance,
www.abcd.com/xyz/page.html
there are about 300 pages indexed by google with the old URL.
Now i have removed that code from the main domain and installed the code in Sub-Domain. So it make all the URLs indexed by Google and all the backlinks are pointing to the old URL.
Now i need to point all the old invalid URL to new Valid URL when Users clicks on the old URL.
Please suggest how to handle this.
Thanks a lot...
If you are using Apache, I suggest that you use mod_rewrite as it allows to send the HTTP status 301 Moved Permanently, informing search engines that the contents of your website has been moved to a new location (rather than just deleted).
In a .htaccess file:
RewriteEngine on
RewriteRule (.*) http://newdomain.mysite.com/$1 [R=301,L]
The first line enables URL "rewriting", the fancy term for redirections of all kind. The second line is decomposed like this:
RewriteRule is the directive to match URLs and change the place they point to;
(.*) is a regular expression matching any requested file path (without an initial slash)
http://newdomain.mysite.com/$1 is the place where you want to send your visitors, and $1 is expanded to the previously matched path
[R=301,L] tells Apache to send the 301 Moved Permanently HTTP status code, and that it's the last RewriteRule that can match this request (it's useful only when you have multiple RewriteRules but it doesn't hurt to have it anyways).
The next time crawlers visit your site, they will notice the HTTP status and update their links to your new address. You should have it set up as soon as possible before Google thinks your whole site went 404.
If you are using Apache as your web server you can use mod_rewrite or mod_alias command. This is more a server job and not a programming job.
You can put the following in a .htaccess file or in the vhost container.
mod_rewrite
RewriteEngine On
RewriteRule ^xyz/page.html$ new-page.php [L,NC,R=301]
See: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
mod_alias
Redirect permanent xyz/page.html http://domain.com/new-page.php
See: http://httpd.apache.org/docs/current/mod/mod_alias.html#redirect
PHP
You can use a Location header to perform a redirection:
header('Location: http://domain.com/new-page.php', true, 301);
Java
public void HttpServletResponse.setHeader(String name, String value)
See: http://docstore.mik.ua/orelly/java-ent/servlet/ch05_06.htm
This should be handled by the server, preferably using an htacces redirect
PHP:
header('Location: new.url.com');

htaccess redirect wordpress folder change

I currently have a url of http://example.com/wordpres/
I'm going to change this to http://example.com/w/
I currently get a lot of traffic from links already out on the web. How can I redirect everything that went to /wordpress to /w ?
RedirectMatch 301 ^wordpress(.*)$ /directory/path/to/w/$1
The above line should match every request coming to your domain with 'wordress' at the start and redirect it to /w/. The '301' tells the browser (and search engines) that the page(s) have moved permenantly. The $1 exists to redirect anything after /wordpress/ and append it to the redirected URL. So if I visit http://example.com/wordpress/this-post/ I would get redirected to http://example.com/w/this-post.
Add this rule to your .htaccess file:
RewriteEngine on
RewriteRule wordpress(.*)$ /w$1
If doesnt work.. let me know... :)

Resources