Replace characters from a URL via . Htaccess

Asked

Viewed 455 times

0

I have the following model of Urls:

http://dominio.com.br/cgi-bin/wiki.pl?Palavra
http://dominio.com.br/cgi-bin/wiki.pl?Outra_Palavra

and need to redirect to this new model:

http://dominio.com.br/#Palavra
http://dominio.com.br/#Outra_Palavra

I want to replace the section cgi-bin/wiki.pl?Palavra for #Palavra when redirecting.

My . htaccess is like this currently:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{HTTP_HOST} ^dominio.com.br
RewriteRule ^ http://www.dominio.com.br%{REQUEST_URI} [L,R=301]
RewriteRule ^cgi-bin/wiki.pl?(.*)$ /#$1 [R=301,NC,L,NE]
</IfModule>

Using this current . htaccess model, you are redirecting: http://dominio.com.br/cgi-bin/wiki.pl?Palavra for: http://dominio.com.br/#?Palavra

Note that the interrogation is still present in the URL after the redirect, but I need it to stay that way: http://dominio.com.br/#Palavra

Note: It seems that whoever created the first structure of Urls (which in the case was not me) used the "Key" of the Query String as a value, and for this reason I am not able to rescue the Key to use in the new structure of Urls. If the URL was http://dominio.com.br/cgi-bin/wiki.pl?chave=Palavra it would be easier to solve, but as it is currently I am not able to solve.

Someone knows how to fix this ?

  • And what are the characters to be replaced justifying the title of your question? If the intention is to make the URL more user friendly, this redirect would not be the other way around, from the second URL to the first?

  • Have you searched the site? Like this question.

  • I did, but so far I have found nothing to help me solve my problem. I edited the question adding more details for a better understanding of the problem.

1 answer

0

I found the solution. Follow .htaccess updated:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{HTTP_HOST} ^dominio.com.br
RewriteRule ^ http://www.dominio.com.br%{REQUEST_URI} [L,R=301]
RewriteRule ^cgi\-bin/wiki\.pl$ /\#%{QUERY_STRING} [QSD,R=301,L,NE]
</IfModule>

Browser other questions tagged

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