Dynamic .htaccess redirect - .htaccess

I'm trying to create an .htaccess redirect so that an folder will redirect to its proper page.
For example... http://example.com/contactus/help.html will redirect to http://example.com/contact-us/help.html or http://example.com/contactus to http://example.com/contact-us

<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^example\.com/contactus/(.+)$ [NC]
RewriteRule ^ http://example\.com/contact-us/%1 [R=301,L]
</IfModule>

Related

What is the code to be added to Redirect from http to https in .htaccess file?

What is the code to be added to Redirect from http to https in .htaccess file?
here is the existing code in .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/NextNext/
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
awaiting your help..
Try this rule after RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

htaccess redirect GET request

I try to redirect some URL with GET request to the new URL with htaccess.
old:
http://example.com/?screenshot=file%20name.jpg
new:
http://example.com/downloader.php?screenshot=file%20name.jpg
I checked similar questions but couldn't handle this.
Add this rule in top of .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} screenshot=(.*)
RewriteRule ^\/$ /downloader.php [QSA,R=301,L]
</IfModule>
or check this modified rule:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} screenshot=(.*)
RewriteRule ^\/$ /downloader.php?screenshot=%1 [R=301,L]
</IfModule>

Page redirection with .htaccess

I need to make a target, when the user access, https://www.dominio.com.br/portal/anything be directed to https://www.domain.com.br/blog
Is it possible to do this with .htaccess?
Here is the code I have:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule .* / [R=200,L]
RewriteRule ^portal/([a-z0-9\-]+)/$ ^blog/ [QSA]
</ifModule>
Note: Inside the portal folder, I already have an index.php pointing to blog. This .htaccess would go inside this folder.
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^portal/(.*) blog/$1 [L,QSA]
</ifModule>

.htaccess make https://www.mysite.com go to https://mysite.com

I'd like my htaccess file to make any url gone to with a www to be removed...
For example, if I was to go to:
https://www.mysite.com
I'd need to be redirected to:
https://mysite.com
The site is SSL encrypted, so all URL's should have https://
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^https://www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
</IfModule>
You can use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(example\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]

How to redirect one url to another url using .htaccess?

I am trying to redirect old url to new url but it is not redirecting.
Old url: http://domain.com/STACK/App/
New url: http://domain.com/stack-app
And my .htaccess file
Redirect 301 /STACK/App http://domain.com/stack-app
Thanks,
Try this code.
RewriteEngine on
RewriteRule http://domain.com/STACK/App/ /http://domain.com/stack-app [R=301,L]
For more help go to this link:--
http://edward-designer.com/web/htaccess-url-rewrite-simplified/
You can use this rule as your very first redirect rule in your root .htaccess:
RedirectMatch 301 ^/STACK/App/?$ /stack-app
Within the mod_rewrite section of your .htaccess file, add the following lines on the old site:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com\STACK\App\$
RewriteRule (.*)$ http://domain.com/stack-app/$1 [R=301,L]
</IfModule>
you can use the following code to redirect your website using .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !oldexample.com$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/$1 [L,R=301]
for non www version, you can use the following,
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !oldexample.com$ [NC]
RewriteRule ^(.*)$ http://newexample.com/$1 [L,R=301]

Resources