I need some help to transform my static .htaccess
rule to a dynamic rule. This is the definition of the rule:
#Redirect the request of file inside folder 'agencias/pagina_agencia/' to the base root URL
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.avantitecnologiati.com.br
RewriteRule ^teste2 agencias/pagina_agencia/teste2.php [L,QSA]
Everytime when someone request the page: [www.avantitecnologiati.com.br/teste2] automatically the htaccess rule reads the file called "teste2.php" which are located at this path:[www.avantitecnologiati.com.br/agencias/pagina_agencia/teste2.php] everything working perfect right?
Nop, I got two problems ;(
- I need to create a new line everytime I add a new file inside the folder called "agencias/pagina_agencia/", something like:
RewriteRule ^teste3 agencias/pagina_agencia/teste3.php [L,QSA]
And that’s not functional, because I am going to create 10k files inside the folder "directory"…
- If the user directly requests [
www.avantitecnologiati.com.br/agencias/pagina_agencia/teste2
], it needs to redirect to the page [www.avantitecnologiati.com.br/teste2
] and wouldn’t display the real location…
Thanks for your time to read my question 😉
FULL HTACCESS CODE
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ avantitecnologiati.com.br$1 [R=301,L]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.avantitecnologiati.com.br
RewriteRule ^teste2 agencias/pagina_agencia/teste2.php [L,QSA]
RewriteRule ^teste3 agencias/pagina_agencia/teste3.php [L,QSA]
#Hide and Redirect Extension
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]+s.+.phpsHTTP/.+
RewriteRule ^(.+).php$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/shtml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
#Custom Error Page
ErrorDocument 404 http://www.avantitecnologiati.com.br/
I am getting a 302 error when try to use the arkascha rule’s, when I request the url: http://www.avantitecnologiati.com.br/ it doesn’t find the file ;(
2
Answers
This probably is what you are looking for:
It is a good idea to start out with a
R=302
temporary redirection and to only change that to aR=301
permanent redirection once everything works as desired. That prevents nasty caching issues …Have it like this (see inline comments) in your site root .htaccess:
Note about relative URLs for including resources in your HTML:
You may hit the most common problem people face when switching to pretty URL schemes i.e. resource not found when using relative paths. Simple solution is to use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with
http://
or a slash/
.Otherwise You can add this just below
<head>
tag of your page’s HTML:<base href="/" />
so that every relative URL is resolved from that base URL and not from the current page’s URL.