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>
Related
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
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]
So I'm using the answer from here to remove the query string: How to remove GET parameters from url with htaccess?
And it works fine in general.
Here are the rules I'm using (in the beginning of the htaccess):
RewriteEngine on
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} !^p=
RewriteRule (.*) https://www.r-bloggers.com%{REQUEST_URI}? [R=301,L]
BUT...
If I browse using a mobile device to this url:
t.co/6raI2VkTse?amp=1
It will redirect me to this url (and will stay there, without a further redirect, even though it has a url parameter):
https://www.r-bloggers.com/how-to-handle-cran-checks-with-help-from-r-hub/amp/?p=182189&__twitter_impression=true
If I then refresh, it will redirect me to:
https://www.r-bloggers.com/how-to-handle-cran-checks-with-help-from-r-hub/
I've tried adding:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)&?__twitter_impression=[^&]+&?(.*)$ [NC]
RewriteRule ^/?(.*)$ /$1?%1%2 [R=301,L]
(from here)
But this also didn't help.
I have no idea why this is happening. Any suggestions?!
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.
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.