[英]Create SEO-friendly URL from php using htaccess
我的网站网址如下:
myhomesite.ext/listino/macchine/listino/marca.php?marca=Audi
我想获得一个类似如下的URL
myhomesite.ext/listino/macchine/listino/marca-Audi/
因此,我尝试使用以下代码
<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>
但什么都没发生,我听不懂,请指出我的错误在哪里。
这是我最近的评论
哦,是的,我正在尝试几种解决方案,但是现在我已经从一个生成器工具中尝试了此代码,
Options +FollowSymLinks
RewriteEngine on
RewriteRule marca/marca/(.*)/ marca.php?marca=$1
RewriteRule marca/marca/(.*) marca.php?marca=$1
如果我继续在mediasportweb.com/macchine/listino/marca/marca/15上找到网址,则在css样式的页面上有很多问题,但是我找到了,但是我也找到了网址mediasportweb.com/macchine/listino /marca.php?marca=15,我认为该指令重写url会删除旧的url,我认为这是什么问题?
请注意,您应该从代码中获取的网址是:
myhomesite.ext/macchine/listino/marca/Audi/
并不是:
myhomesite.ext/macchine/listino/marca-Audi/
改成
RewriteRule ^marca\-([a-zA-Z0-9]+)/$ marca.php?marca=$1
从
RewriteRule ^marca/([a-zA-Z0-9]+)/$ marca.php?marca=$1
将此规则放在/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]
对于css / js等,请在css,js,图像文件中使用绝对路径,而不要使用相对路径。 这意味着您必须确保这些文件的路径以http://
或斜杠/
开头。
您可以尝试将其添加到页面的HTML标头中: <base href="/" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.