Category Archives: redirect

htaccess redirect all domain except one subfolder including the files and other subfolders inside

I'm currently using:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder/.*
RewriteCond %{REQUEST_URI} !^/folder$
RewriteRule .* [R=301,L]

Which works great at redirecting the "folder" to the "newdomain," including the files within that folder, however, the subfolders within that folder still redirect.

I've tried:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder/.*
RewriteCond %{REQUEST_URI} !^/folder$
RewriteCond %{REQUEST_URI} !^/folder/subfolder/.*
RewriteCond %{REQUEST_URI} !^/folder/subfolder$
RewriteRule .* [R=301,L]

As well as:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder/.*
RewriteCond %{REQUEST_URI} !^/folder$
RewriteCond %{REQUEST_URI} !^/subfolder/.*
RewriteCond %{REQUEST_URI} !^/subfolder$
RewriteRule .* [R=301,L]

with no luck.

Any suggestions?

WordPress .htaccess redirection issue

Recently, I moved from a static website to a WordPress made website. Everything works perfectly except one thing.

My company uses players to display content and the players call an url like this to get the content :

This url is from the old website. As the new website is on WordPress now, the url is a more "classic" one :

The best solution would be to make the players calling the new url but it's impossible. So I thought about doing a redirection with the .htaccess but it doesn't work.

Here's my .htaccess :

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Redirect 301

Even with the redirection, when I call I land on the main page and not the page I want.
What can I do to have my redirection working ?

Directory Redirect to HTML Document not working

On a website I have a directory service-name which I don't want people to have access to, since it just stores css files, images and pdfs. Further more, in a different folder on the site, at the web root, there is a page service-name.html.

To stop the directory listing, in the service-name folder, I have included a .htaccess file and an index.html file.

Within the .htaccess file I have put Options -Indexes to disable the directory listing, and then put in RewriteRule ^index.html [R=301,L]

So in short I am trying to redirect the search for the directory to a root level html page. It is not working though. I get a blank page with the service-name directory, which I guess works adequatley because my desire to stop people accessing a directory has come to fruition, but it does not redirect straight to the desired page, which I thought it would have if I included the index.html page in the directory and redirected that?

But when you search for service-name/index.html that redirects properly, so I have clearly missed something! A sharp prod in the right direction would be of use!


Apache Redirect with subdirectories

This is my current setup:

<VirtualHost *:443>
        Redirect "/something" ""        
        RedirectPermanent /

        Include includes/

        # Enable SSL
        Include ssl-conf/product_ssl.conf

# Redirect non-www to wwww
<VirtualHost *:443>
        RedirectPermanent /
        Include ssl-conf/product_ssl.conf

# Redirect non-www http to https
<VirtualHost *:80>
        RedirectPermanent /

# Redirect www http to https
<VirtualHost *:80>
        Define proxy_host
    RedirectPermanent /

I want everyone going to to be redirected to a certain website. However when someone goes to I want them to be redirected to a different website.

Problem now is that will not be redirected, but the original site is shown. And this also causes the /something to not be redirected as well.

Apache redirects overwriting inconsistently

I have multiple rewrite rules configured for a domain, to serve specific articles by 301ing to a new domain, and two catch-all rules for rules that don't match

RewriteEngine on
# Rewrites for specific pages to a new server
RewriteRule "^/2018/04/01/Article-1/$" "" [R=301,L]
RewriteRule "^/2018/04/02/Article-2/$" "" [R=301,L]
# Catch-all for images (pass them through)
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC]
# Redirect for all other matches
RewriteRule ^(.*)$ [R=301,L]

The issue I am running into is that while Article-1 matches fine and serves a 301, requests to Article 2 appear to be caught up by the last rule in the redirect. I'm not entirely sure why this is occurring, but any advice would be helpful, before I add the remaining 6400 entries to the redirect file.

To help with debugging, here's the markup for a curl call to the article 2 test path:

curl -0 -o example.html

<title>301 Moved Permanently</title>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="$%224">here</a>.</p>
<address>Apache/2.4.18 (Ubuntu) Server at Port 80</address>

Apache redirection to another port

I'm in trouble with understanding the apache configuration to redirect an http to another. I need to redirect the following: to and to

I have seen that with that lines it redirects to another address, but I need to know if it will work before doing anything.

Redirect permanent "/foo" "" Redirect permanent "/bar" ""

Thank you!

Specific 301 redirects

I have a specific request for htaccess redirects. I still don't know if it's possible:

  • Redirecting all of my domains to one https domain with www in front.

  • That one https domain should also be redircted from https-non-www to https-www.

  • Additionally excluded from that should be 2 subdomains on http

Really excited. Thanks in advance.

Trying to rewrite a local url to another

I want to be able to do the following:

ReWrite /test -> /test.php


ReWrite /Test/test -> /Test/test.php

I want to be able to do this only for those mentioned urls. Also, I do not want direct access to .php urls. For example, if the user navigates to /Test/bla.php or any other links, he would be automatically be directed to the /index. The main reason I am doing this is that I do not want the user to know I am using .php. Here is what I tried:

RewriteEngine On
RewriteRule ^Test/test$ /Test/test.php
RewriteRule ^test$ test.php
ErrorDocument 404 /index.php

This works to some extent. I can navigate to /Test/test and it redirects me to /Test/test.php without issues. Though, if I do something like /test (from the root), I see the Test folder instead. Also, 404 does not work in this .htaccess above. I can navigate to any missing url and it complains that it is not there.

I am new to web hosting. So, I am kind of confused by the .htaccess.

Thanks for your time.