I don't think this is possible, however I would like to ask the community to see if it is.
I have a blog on a subdomain blog.domain.com due to a revamp of the site we are having to use the blog on a trailing domain domain.com/blog this isnt ideal as all our old post permalinks point to the subdomain.
I was therefore wondering if there is a way to use the .htaccess to rewrite domain.com/blog -> blog.domain.com
Any help would be greatly appreciated.
I believe you want to redirect all the traffic from blog.domain.com to domain.com/blog. Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(blog)\.(domain\.com)$ [NC]
RewriteRule ^ http://%2/%1%{REQUEST_URI} [NE,R=302,L]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
Related
I want to redirect my old website as directory of my new website.
olddomain.tld = newdomain.tld/directory/
Redirect 301 / https://newdomain.tld/directory/
But when i set
Redirect 301 /contactus/ https://newdomain.tld/contact-us/
result is https://newdomain.tld/directory/contact-us/ 404, because of wrong path.
How can resolve this issue?
Best regards
I suggest you avoid Redirect and use more powerful mod_rewrite engine.
You may use these rules on your old host's .htaccess:
RewriteEngine On
RewriteRule ^contactus/(.*)$ https://newdomain.tld/contact-us/$1 [L,NC,R=301,NE]
RewriteRule ^(.*)$ https://newdomain.tld/directory/$1 [L,NE,R=301]
Make sure to clear your browser cache.
References:
Apache mod_rewrite Introduction
.htaccess tips and tricks
I am using .htaccess redirect in my website. I am using those code
Redirect /addgiftmr/widgetjs.aspx https://www.mysite.com/
But when redirect, it is adding extra word. I am getting url as https://www.mysite.com/?route=addgiftmr/widgetjs.aspx
how can I remove ?route=addgiftmr/widgetjs.aspx form link?
Here is how to do it in .htaccess if mod-rewrite is installed. The advantage of mod-rewrite is that it is easier to expand later if you want to use more complex rules.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^addgiftmr/widgetjs.aspx https://www.mysite.com/ [L,R]
Hi I need to redirect using htaccess every request which points at:
http://www.mydomain.com/index.php?option=com_content&view=category&layout=blog&id=293&Itemid=387
to this url:
http://www.otherdomain.com
I've try to do it by:
redirect /index.php?option=com_content&view=category&layout=blog&id=293&Itemid=387 http://www.otherdomain.com
But it doesnt work. So I need Your help.
Better to use mod_rewrite for this stuff.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^option=com_content&view=category&layout=blog&id=293&Itemid=387$
RewriteRule ^index\.php$ /? [L,R=302,NC]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
I think someone may need to extend my answer but you'll be looking to do something along the lines of:-
RewriteRule ^([^/]+)/? index.php?option=$1 [R=301,L]
The rule will require a regular expression so the server can compare the request.
I need to redirect from:
/shop/ to /shop/pay-your-bill/
At the moment in my .htaccess file I have:
Redirect /shop/ http://url/shop/pay-your-bill/
This however results in this error:
The web page at URL/shop/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Is there a way to redirect shop to pay-your-bill correctly?
Thanks!
You can use RedirectMatch like this:
RedirectMatch 302 ^/shop/?$ /shop/pay-your-bill/
Or if you can use mod_rewrite then use:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^shop/?$ /shop/pay-your-bill/ [L,R,NC]
You can try this
rewriterule ^/shop/(.*) http://url/shop/pay-your-bill/ [r=301,nc]
This is my .htaccess
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^genre/(.*)$ /index.php?genre=$1 [R=301]
The mod_rewrite works, but so does the old link example:
/index.php?genre=action
Still works. I want to redirect it to:
/genre/action
Problem: They both work, I want the old one to redirect to the new one.
And is it possible to change links with .htaccess. Some sort of url replacing?
My links still says:
www.site.com/index.php?genre=action
I want it to change it to:
www.site.com/genre/action
Or do I have to do this manually?
Thanks!
[R=301] leads to a HTTP redirect with status code 301.
Just write
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^genre/(.*)$ /index.php?genre=$1
to rewrite the urls on the server side.