Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

linus_sp

Como fazer um rewrite replace no .htaccess?

Recommended Posts

Estou fazendo um site em PHP rodando num Linux server e estou tendo um problema.

 

Tenho a rewrite condition feita no htaccess que cria URL amigaveis, o problema é que as urls não ficam tão "amigáveis"assim quando o titulo possui acentuacao, pois ela conveter a palavra acentuada em um monte de letras sem sentido.

 

Preciso saber como faço para que ele substitua as letras com acentos por letras sem acentuacao na URL, por exemplo, substituir o "'é" por "e", "'ç" por "c", etc.

 

O código atual está assim:

 

Options -MultiViews +FollowSymlinksRewriteEngine On<IfModule mod_security.c>	# Turn off mod_security filtering.  	SecFilterEngine Off	# The below probably isn't needed, but better safe than sorry.	SecFilterScanPOST Off</IfModule><IfModule !mod_php4.c>	<IfModule !mod_php5.c>		# PHP is in CGI Mode, so we need a different mod_rewrite		RewriteCond %{REQUEST_URI} !categories\.php		RewriteRule ^categories(.*) categories.php?$1 [L]				RewriteCond %{REQUEST_URI} !articles\.php		RewriteRule ^articles(.*)$ articles.php?$1 [L]		RewriteCond %{REQUEST_URI} !pages\.php		RewriteRule ^pages(.*)$ pages.php?$1 [L]				RewriteCond %{REQUEST_URI} !blogs\.php		RewriteRule ^blogs(.*)$ blogs.php?$1 [L]				RewriteCond %{REQUEST_URI} !search.php		RewriteRule ^search(.*)$ search\.php?$1 [L]				RewriteCond %{REQUEST_URI} !authors.php		RewriteRule ^authors(.*)$ authors\.php?$1 [L]				RewriteCond %{REQUEST_URI} !articlerss.php		RewriteRule ^articlerss(.*)$ articlerss\.php?$1 [L]				RewriteCond %{REQUEST_URI} !news.php		RewriteCond %{REQUEST_URI} !newsrss.php		RewriteRule ^news(.*)$ news.php?$1 [L]				RewriteCond %{REQUEST_URI} !contact.php		RewriteRule ^contact(.*)$ contact\.php?$1 [L]			</IfModule>	<IfModule mod_php5.c>				# Using PHP 5 in module mode		RewriteCond %{REQUEST_URI} categories.*		RewriteRule ^categories(.*)$ categories.php?$1 [T=application/x-httpd-php,L]		RewriteCond %{REQUEST_URI} articles.*		RewriteRule ^articles(.*)$ articles.php?$1 [T=application/x-httpd-php,L]		RewriteCond %{REQUEST_URI} pages.*		RewriteRule ^pages(.*)$ pages.php?$1 [T=application/x-httpd-php,L]		RewriteCond %{REQUEST_URI} blogs.*		RewriteRule ^blogs(.*)$ blogs.php?$1 [T=application/x-httpd-php,L]		RewriteCond %{REQUEST_URI} search.*		RewriteRule ^search(.*)$ search.php?$1 [T=application/x-httpd-php,L]		RewriteCond %{REQUEST_URI} authors.*		RewriteRule ^authors(.*)$ authors.php?$1 [T=application/x-httpd-php,L]		RewriteCond %{REQUEST_URI} articlerss.*		RewriteRule ^articlerss(.*)$ articlerss.php?$1 [T=application/x-httpd-php,L]		RewriteCond %{REQUEST_URI} news.*		RewriteCond %{REQUEST_URI} !newsrss		RewriteRule ^news(.*)$ news.php?$1 [T=application/x-httpd-php,L]				RewriteCond %{REQUEST_URI} contact.*		RewriteRule ^contact(.*)$ contact.php?$1 [T=application/x-httpd-php,L]	</IfModule></IfModule><IfModule mod_php4.c>	# PHP 4 in module mode	RewriteCond %{REQUEST_URI} categories.*	RewriteRule ^categories(.*)$ categories.php?$1 [T=application/x-httpd-php,L]	RewriteCond %{REQUEST_URI} articles.*	RewriteRule ^articles(.*)$ articles.php?$1 [T=application/x-httpd-php,L]	RewriteCond %{REQUEST_URI} pages.*	RewriteRule ^pages(.*)$ pages.php?$1 [T=application/x-httpd-php,L]	RewriteCond %{REQUEST_URI} blogs.*	RewriteRule ^blogs(.*)$ blogs.php?$1 [T=application/x-httpd-php,L]	RewriteCond %{REQUEST_URI} search.*	RewriteRule ^search(.*)$ search.php?$1 [T=application/x-httpd-php,L]	RewriteCond %{REQUEST_URI} authors.*	RewriteRule ^authors(.*)$ authors.php?$1 [T=application/x-httpd-php,L]	RewriteCond %{REQUEST_URI} articlerss.*	RewriteRule ^articlerss(.*)$ articlerss.php?$1 [T=application/x-httpd-php,L]	RewriteCond %{REQUEST_URI} news.*	RewriteCond %{REQUEST_URI} !newsrss	RewriteRule ^news(.*)$ news.php?$1 [T=application/x-httpd-php,L]		RewriteCond %{REQUEST_URI} contact.*	RewriteRule ^contact(.*)$ contact.php?$1 [T=application/x-httpd-php,L]</IfModule>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá amigo, algum tempo atraz passei por isso então vou tentar ajudar.

 

Para resolver esse problema, eu fiz o seguinte, ao inves de corrigir qualquer coisa no proprio .htaccess eu mudei meus links, ou seja, substitui www.meusite.com/notícia/id_notícia/título_da_notícia.html por www.meusite.com/noticia/id_noticia/titulo_da_noticia.html

 

Para fazer isso usei o comando ereg_replace do php

$string = ereg_replace( "[ÁÀÂÃÄ]", "A", $string);
		$string = ereg_replace( "[áàâãäª]", "a", $string);
		$string = ereg_replace( "[ÉÈÊË]", "E", $string);
		$string = ereg_replace( "[éèêë]", "e", $string);
		$string = ereg_replace( "[ÍÌÎÏ]", "I", $string);
		$string = ereg_replace( "[íìîï]", "i", $string);
		$string = ereg_replace( "[ÓÒÔÕÖ]", "O", $string);
		$string = ereg_replace( "[óòôõöº]", "o", $string);
		$string = ereg_replace( "[ÚÙÛÜ]", "U", $string);
		$string = ereg_replace( "[úùûü]", "u", $string);
		$string = str_replace( "Ç", "C", $string);
		$string = str_replace( "ç", "c", $string);
		$string = str_replace( "ñ", "n", $string);

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.