Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为seo友好url编写htaccess重写规则 我刚刚接触.htaccess 我需要一些URL的重写规则 我用谷歌搜索了一些,并申请了一些,但URL没有变化_.htaccess_Mod Rewrite - Fatal编程技术网

如何为seo友好url编写htaccess重写规则 我刚刚接触.htaccess 我需要一些URL的重写规则 我用谷歌搜索了一些,并申请了一些,但URL没有变化

如何为seo友好url编写htaccess重写规则 我刚刚接触.htaccess 我需要一些URL的重写规则 我用谷歌搜索了一些,并申请了一些,但URL没有变化,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我想: 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 但没有区别 谢谢 非常感谢您的帮助。首先,确保在Apache配置中启用了mod

我想:

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
但没有区别

谢谢

非常感谢您的帮助。

首先,确保在Apache配置中启用了mod_rewrite,并且允许使用htaccess文件

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

这将把
example.com/section.php?id=X
变成
example.com/section/X

我建议将URI存储在数据库中,然后使用section.php?URI=

例如:

example.com/section.php?uri=super-awesome

将变成:


example.com/section/super awesome

可能的副本您能否粘贴完整的
.htaccess
?是否安装并启用了“重写”模块?通常不鼓励打开链接,这就是我在评论中添加此内容的原因。每一个mod_重写初学者都必须阅读。勒曼:谢谢你。它工作得很好。有一件事我想问。现在我必须相应地修改我的php代码。我的意思是必须解释并获得章节标题?实际上,您不必更改任何内容,因为您仍然获得
id
参数“在后面”(隐藏)。我不确定我是否理解你的问题,如果不是这样,请解释是的,这就是我想知道的关于身份证的问题。但在应用此访问之后。我收到404错误。您尝试的url是什么?另外,确保mod_rewrite已启用,并且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]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^section/([^/]+)$ /section.php?id=$1 [L]