Redirect extensions and folders with .htaccess

7

I'm in all ways trying to create a redirect with htaccess and I got it like this:

<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
Options +FollowSymLinks
RewriteCond %{REQUEST_URI} !^/(?:index\.php|robots\.txt)$ 
RewriteRule (.*) http://meusite.com/novapasta/$1 [R=301,L]
</ifModule>  

The problem that at the time I type in the URL any file other than index.php or robots.txt it plays into that folder.

Ex: sitemap.xml it is targeting myite.com/novapasta/sitemap.xml and I do not want this.

I tried to put:

RewriteCond %{REQUEST_URI} !^/(?:index\.php|robots\.txt|sitemap\.xml)$ 

But it does not accept and direct from the root to /novapasta/sitemap.xml folder

Until folders it is directing.

Ex: meusite.com/imagens to meusite.com/novapasta/imagens/

How can I stop this?

What I need:

So I always test in private mode and it still directs. I actually have a site that it had a querystring that makes the links stay

  • http://meusite.com/produto.php?produto=$1

  • http://meusite.com/produto

Now I want to play everything into this new folder

  • http://meusite.com/novapasta/produto

Only with this redirect if I try to access:

http://meusite.com/sitemap.xml , http://meusite.com/imagens/ and http://meusite.com/diretorioqualquer

he plays for:

http://meusite.com/novapasta/sitemap.xml , http://meusite.com/novapasta/imagens/ e http://meusite.com/novapasta/diretorioqualquer

The only ones he does not play are the index and the robots and he would like to play only what comes from produto.php?produto=$1

So I always test in private mode and it still directs. I actually have a site that it had a querystring that makes the links stay

link $ 1

link

Now I want to play everything into this new folder

link

Only with this redirect if I try to access

link

link

link

He plays for

link

link

link

The only ones he does not play are the index and the robots and he would like to play only what comes from the product.php? product = $ 1

    
asked by anonymous 21.05.2015 / 00:59

1 answer

1

When the browser receives a 301 this is cached, so this works:

RewriteCond %{REQUEST_URI} !^/(?:index\.php|robots\.txt|sitemap\.xml)$

The problem is that for the browser the old page no longer exists because you used the flag R=301 .

To resolve this, clear the cache and re-open the browser or open the browser in Private mode.

Note that your rewritecond blocks any url except: index.php and robots.txt and sitemap.xml.

You asked:

  

How can I stop this?

I do not quite understand what you want, if you do not want any url to be blocked then you will have to understand what you are doing, because your code tells you to do this exactly. The practical solution would be to not use .htaccess .

    
21.05.2015 / 01:17