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 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥150 求 《小魔指》街机游戏机整合模拟软件