duanlie2709 2014-06-13 11:01
浏览 54
已采纳

使用htaccess从php创建SEO友好的URL

I have a problem where my site url is as below;

myhomesite.ext/listino/macchine/listino/marca.php?marca=Audi

and I want to obtain an url similar as follows

myhomesite.ext/listino/macchine/listino/marca-Audi/

So, I try with the following code

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
</IfModule>


<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^marca/([a-zA-Z0-9]+)/$ marca.php?marca=$1
</IfModule>

but nothing happened, I don't understand and please point me out where is my mistake.

This is my latest add from the comment

Oh yes it's correct i am trying several solutions, but now i 've tried this code from one generator tool it's

 Options +FollowSymLinks 
RewriteEngine on 
RewriteRule marca/marca/(.*)/ marca.php?marca=$1 
RewriteRule marca/marca/(.*) marca.php?marca=$1  

if i go on mediasportweb.com/macchine/listino/marca/marca/15 i find the url, with many problem on page on the css style, but i find it, but i also find the url mediasportweb.com/macchine/listino/marca.php?marca=15, i think that directive rewrite url erase the old url, what is wrong in my think?

  • 写回答

3条回答 默认 最新

  • dpp80346 2014-06-13 12:54
    关注

    Place this rule in /macchine/listino/.htaccess:

    RewriteEngine On
    RewriteBase /macchine/listino/
    
    RewriteCond /marca\.php\?marca=([^\s&]+) [NC]
    RewriteRule ^ marca/marca/%1? [R=302,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule marca/marca/([^/]+)/?$ marca.php?marca=$1 [L,QSA,NC]
    

    For css/js etc 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 /.

    You can try adding this in your page's HTML header: <base href="/" />

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器