1
I don’t have much experience with . htaccess and am having some difficulty rewriting a website’s Urls.
On the site in question, I first forced the rewriting of the URL to HTTPS (the site did not have SSL before):
Options +FollowSymlinks
ErrorDocument 404 https://www.dominio.com.br/pagina404.html
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Then I redirected 301 dominio.com.br for www.dominio.com.br successfully. The rule also applies to index or index.php after the base URL (eg: www.dominio.com.br/index.php).
RewriteCond %{HTTP_HOST} ^dominio\.com\.br
RewriteRule ^(.*) https://www.dominio.com.br/$1 [R=301,L]
RewriteRule ^index(/|.php)?$ https://www.dominio.com.br [R=301,L]
So far, everything worked. It turns out that the Urls on this site are not friendly. They follow the pattern below:
www.dominio.com.br/index.php? link=about
As the rewrite removes the index, they look like this:
www.dominio.com.br/? link=about
So I force the rewrite using the snippet below, to try a URL like this: www.dominio.com.br/about
RewriteRule ^\?link=(.*) /$1
RewriteRule ^/(.*)(.php)?\?link=(.*) /$3
This was one of the rules I tried, including testing in Sublime/netbeans, using the regex of them working out there. It turns out that when you test on the server, no rewriting occurs. I tested several other rules by reading the documentation, such as [NC],[L] among others. Some result in 500 error.
So my question is whether the use of Https, the deletion of the index or the server itself may be affecting these rewrites?
Note: I tried some of the options shown on other topics, like these:
See if it helps: answer 1, answer 2
– Papa Charlie
Implementing Router-Friendly URL
– marcusagm