Hide directory with htaccess

Asked

Viewed 363 times

1

Colleagues.

I have the following htaccess code that I direct:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?site.com.br$
RewriteCond %{REQUEST_URI} !^/novo/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /novo/$1
RewriteCond %{HTTP_HOST} ^(www.)?site.com.br$
RewriteRule ^(/)?$ novo/index.php [L]

But there are links that contain new/company.php and I would like the click to appear only php company. without having to change the links in the menus. You can do this in htaccess?

1 answer

1


You can use 301 redirect in that case. It would look something like this:

redirect 301 /novo/empresa.php http://www.seusite.com.br/empresa.php

I hope I’ve helped.

Update
How is it not a url just, you must make a rule of RewriteEngine
It would look something like this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+novo/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^novo/)^(.*)$ /novo/$1 [L,NC]

Reference: https://stackoverflow.com/questions/18361419/hide-directory-name-from-url/18361995#18361995

You can see that this problem is common in the community:
https://stackoverflow.com/questions/30194198/how-can-i-hide-folder-name-from-url-using-htaccess
https://stackoverflow.com/questions/18361419/hide-directory-name-from-url/18361995#18361995
https://stackoverflow.com/questions/14770442/hiding-folder-in-url-using-htaccess
https://stackoverflow.com/questions/17642122/htaccess-hiding-a-directory-in-the-url-while-preserving-other-files
https://stackoverflow.com/questions/18361419/hide-directory-name-from-url

I hope I’ve helped.

  • 1

    Hi Ricardo. I used the company.php page as an example, but if it’s just the directory, can I use it this way? redirect 301 /new/$1 http://www.seusite.com.br/$1

  • Obrigado Ricardo.

Browser other questions tagged

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