如何为Seo友好的URL编写htaccess重写规则

艾哈迈德·阿里
  • 我刚来.htaccess
  • 我需要一些重写规则URLs
  • 我用了Google,并应用了但网址没有变化。

我想要:

demo.example.com/section.php?id=1 

变成:

demo.example.com/section/sample-section

我试过了

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^section/(\d+)*$ ./section.php?id=$1

但没有区别

谢谢。

感谢您的帮助。

贾斯汀·欧曼

首先,确保mod_rewrite的启用和htaccess的文件允许在你的Apache配置。

然后,将此代码放入您的htaccess中(必须位于根文件夹中)

Options -MultiViews
RewriteEngine On

# redirect "/section.php?id=xxx" to "/section/xxx"
RewriteCond %{THE_REQUEST} \s/section\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /section/%1? [R=301,L]

# internally rewrite "/section/xxx" to "/section.php?id=xxx"
RewriteRule ^section/([0-9]+)$ /section.php?id=$1 [L]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章