URL Rewrite from "bare" domain to specific URL - nginx

I need to redirect so when someone types https://mydomain.is to be redirected to https://mydomain.is/issues, I found directive how to do oposite, but not what I want.
mydomain.is is site hosted in plesk.
Desired output:
https://mydomain.is --> https://mydomain.is/issues
Found this guide, but when i click Apply, it shows that web site is about to be deleted

Have you tried using mod_rewrite? For example insert this at the beginning of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.is$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.is$
RewriteCond %{REQUEST_URI} !^/issues
RewriteRule (.*)$ /issues/$1

Related

Wildcard subdomains only working with double slash(//)

I have created wildcard subdomains based on username. However it is working fine but only issue which occurs it that its working with double slashes at the end. For example johndoe.example.com// and if i use johndoe.example.com/ it redirects me to main domain example.com. I am not sure why this is happening and what to i have to do in .htaccess file. I tried many things in htaccess but it is not working.
Expected URL - username.example.com
Actual URL - example.com/user/username
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com$ [NC]
RewriteRule ^/?$ /user/%1 [L]

Single URL mod_rewrite keeps going back to the original URL

I am trying to do a very simple single URL rewrite.
This is it:
RewriteRule ^blog /?post_type=post [NC,L]
I would simply like example.com/?post_type=pos to redirect and display example.com/blog.
I have tried a number of different versions of the rewrite but all I have achieved thus far is that I don't get a 404 on example.com/blog but keeps going back to example.com/?post_type=post.
I have placed RewriteRule right at the top of the .htaccess file which didn't help.
These are the other rewrites I have in the same .htaccess file:
#Single URL
RewriteRule ^blog ?post_type=post [NC,L]
#http www rewrite
RewriteCond %{HTTP_HOST} ^instrumentrentalbarcelona.com [NC]
RewriteRule ^(.*)$ https://www.instrumentrentalbarcelona.com/$1 [L,R=301,NC]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thank you #DocRoot for helping me with this. The answer is detailed in the comment thread below by DocRoot and I. Just thought I would summarise this.
I wanted to show a page with all my blog posts.
This can be done if you use the WordPress post type "Post". example.com/?post_type=post
I wanted that page to show when you go to example.com/blog.
The following Rewrite works to show the desired URL: (thank you again #DocRoot)
RewriteCond %{QUERY_STRING} ^post_type=post$
RewriteRule ^$ /blog [QSD,R,L]
But /blog was giving a 404. So;
Create a page in WordPress called "blog"
Go to: Setting > Reading > Your homepage displays > Posts page: [Select page "blog"]
Save and done.
RewriteRule ^blog /?post_type=post [NC,L]
I would simply like example.com/?post_type=pos to redirect and display example.com/blog
The directive you posted does the exact opposite. It "rewrites" (not "redirects") from /blog<anything> to /?post_type=post
To redirect based on the query string you need an additional condition that checks against the QUERY_STRING server variable because the URL that is matched by the RewriteRule pattern is the URL-path only.
Try the following instead:
RewriteCond %{QUERY_STRING} ^post_type=post$
RewriteRule ^$ /blog [QSD,R,L]
This "redirects" from example.com/?post_type=post (exactly) to example.com/blog.
The QSD flag (Apache 2.4+) is required to remove the query string from the redirected request. If you are still on Apache 2.2 then you will need to append the substition with ? instead of using the QSD flag. eg. RewriteRule ^$ /blog? [R,L].
Not also, this is a temporary (302) redirect. If this should be permanent, then change the R flag to read R=301 - but only once you have confirmed this is working OK.

Using .htaccess to point primary domain to subfolder without altering the URL

I have a domain i.e www.domain.org and want to point it to a subfolder on my server. The main domain loads from /public_html and now, I want to load the domain from /public_html/domain2017.
I have researched various solutions on the web, but all I get is a redirect.
The redirect is not preferred because I end up with www.domain.org/domain2017 when I want to stay as www.domain.org but load the index.php file of www.domain.org/domain2017. Hopefully, this makes sense. Note: I have a WordPress installation within public_html/domain2017.
Below is example content of my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.org$ [NC]
RewriteRule !^subdir/ /domain2017%{REQUEST_URI} [L,NC]
</IfModule>
Solution Attempt 1 Solution Attempt 2 Solution Attempt 3 Solution Attempt 4
I have tried all of the above links and they simply redirect my domain to the URL and does not prevent the URL in the address bar from changing
You can use the following htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
RewriteCond %{REQUEST_URI} !public_html/domain2017/
RewriteRule (.*) /public_html/domain2017/$1 [L]

mod_rewrite: insert index.php if URL contains X

I'm trying to use mod_rewrite to change:
http://example.com/?wpdmact=process&did=m5d4FG3
to:
http://example.com/index.php?wpdmact=process&did=m5d4FG3
I just want to insert index.php.
Here is the code I have tried, but that is not working:
RewriteCond %{QUERY_STRING} wpdmact=process&did=(.*)
RewriteRule (.*) /index.php?wpdmact=process&did=%1 [R=301,L]
I have successfully created the following similar redirect on this same site:
RewriteCond %{QUERY_STRING} page_id=(.*)&preview=true
RewriteRule (.*) /index.php?page_id=%1 [R=301,L]
I have a Wordpress site that has a static index.html in the root folder along with index.php. This is to have a lighter, faster loading homepage. The only challenges this has created are the two I'm mentioning here. It breaks because in these instances the site redirects to index.html, instead of index.php.
I don't do a lot of work with mod_rewrite, so any help you can offer is greatly appreciated.
This should work:
RewriteCond %{QUERY_STRING} wpdmact=process&did= [NC]
RewriteRule ^$ /index.php [R=301,L]
QUERY_STRING is automatically carried over to new URL.

RewriteRule in htaccess change url without content

I have one site with wordpress that have blog page.
So now for this page Url is somthing like http://abc.com/blog.
But i want to convert this url to http://blog.abc.com
I added code in .htaccess file but rewrite is not working. Rewrite mode is also on in apache.
Any one have idea how t o change this url ?
I want to test in my local wamp first, so please give suggestion with localhost too, if possible.
Code is that i tried
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc\.com/blog [NC]
RewriteRule http://blog.abc [R=301,L]
Your rule needs to look something like:
RewriteCond %{HTTP_HOST} ^abc\.com$ [NC]
RewriteRule ^blog/(.*)$ http://blog.abc.com/$1 [R=301,L]
the %{HTTP_HOST} variable is only the hostname, and no path information is part of it (e.g. /blog). The RewriteRule takes at least 2 parameters:
RewriteRule <pattern to match against the URI> <if matched, rewrite/redirect to this URL> <flags>

Resources