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 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动