Block redirect of extensions and folders with . htaccess

Asked

Viewed 569 times

7

I’m trying to create a redirect with htaccess and I got it in the following way:

<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 when I type in the URL any other file that is not index.php or robots.txt it plays to this folder.

Ex: sitemap.xml it is directing meusite.com/Novafolder/sitemap.xml and I don’t want that.

I tried to put:

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

But it does not accept and directs from root to /Novafolder/sitemap.xml folder

Even folders he’s directing.

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

How can I stop it?

What I need:

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

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

  • http://meusite.com/produto

Now I want to throw 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/ and http://meusite.com/novapasta/diretorioqualquer

The only ones he doesn’t play are index and robots and would like to play only what comes from produto.php?produto=$1


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

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

http://meusite.com/product

Now I want to throw 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/

http://meusite.com/diretorioqualquer

he plays for

http://meusite.com/novapasta/sitemap.xml

http://meusite.com/novapasta/imagens/

http://meusite.com/novapasta/diretorioqualquer

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

  • I answered briefly, but from what I understand it looks like you’re wearing a .htaccess without knowing exactly what you want, I mean you want one thing, but your htaccess is doing something totally different than what you need. Tell me you really want to block all urls and release just a few? Because if this is it, your htaccess is ok, but if not then your htaccess has no meaning for your project.

  • I don’t really have much knowledge on . htaccess so I’m racking my brain with various tests

  • Tell me you really want to block all urls and release just a few?

  • Depends on the server has permission to configure htaccess, and nothing easy to set up, if it is Locaweb is claim support, recommend to use cPanel is useful to use and will help, and the IIS server can much trampo. Search for "URL friendly" can help.

1 answer

1

Rafael when the browser receives a 301 this is in the cache, 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 open the browser again or open the browser in mode Privy.

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

Did you ask:

How can I stop it?

I don’t quite understand what you want, if you don’t want any url to be blocked, then you’ll have to understand what you’re doing, because your code tells you to do it exactly. The practical solution would be not to use the .htaccess.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.