如何写的搜索引擎友好的URL的htaccess重写规则 [英] How to write htaccess rewrite rule for seo friendly url

查看:179
本文介绍了如何写的搜索引擎友好的URL的htaccess重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我只是新的的.htaccess
  • 在我需要的网​​址部分重写规则。
  • 在我Google'd一些和应用,但在URL没有变化。
  • I am just new to .htaccess.
  • I need some rewrite rules for URLs.
  • I Google'd some and applied but no change in URL.

我想:

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

但没有什么区别

but no difference

感谢。

我会AP preciate你的帮助。

I will appreciate your help.

推荐答案

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

First, make sure mod_rewrite is enabled and htaccess files allowed in your Apache configuration.

然后,把你的htaccess这个code(其中有是在根文件夹)

Then, put this code in your htaccess (which has to be in root folder)

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]

这篇关于如何写的搜索引擎友好的URL的htaccess重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆