使用干净的URL代码创建一个.htaccess文件

时间:2018-08-14 06:51:13

标签: php .htaccess

我想创建干净的URL,因此尝试了许多配置。我还创建了一个.htaccess文件,但是它不起作用。有人可以帮助我吗?

我的.htaccess代码

Options +FollowSymLinks
RewriteEngine on
RewriteRule single-post/id/(.*)/title/(.*)/ single-post.php?id=$1&title=$2
RewriteRule single-post/id/(.*)/title/(.*) single-post.php?id=$1&title=$2   

当前网址

http://localhost/just2minute/story/single-post/id/2590/title/%E0%A4%95%E0%A5%87%E0%A4%B0%E0%A4%B2%20%E0%A4%AE%E0%A5%87%E0%A4%82%20%E0%A4%AC%E0%A4%BE%E0%A4%B0%E0%A4%BF%E0%A4%B6%20%E0%A4%94%E0%A4%B0%20%E0%A4%B2%E0%A5%88%E0%A4%82%E0%A4%A1%E0%A4%B8%E0%A4%B2%E0%A4%BE%E0%A4%87%E0%A4%A1%20%E0%A4%B8%E0%A5%87%2018%20%E0%A4%B2%E0%A5%8B%E0%A4%97%E0%A5%8B%E0%A4%82%20%E0%A4%95%E0%A5%80%20%E0%A4%AE%E0%A5%8C%E0%A4%A4/

我要创建”

http://localhost/just2minute/story/single-post/id/(Any Value)/title/(Any Value)/

1 个答案:

答案 0 :(得分:0)

您不需要两个规则。您可以使用一种重写规则来实现该目标,例如

RewriteRule ^story/single-post/id/([0-9]+)/title/([0-9a-zA-Z-]+)/?$ single-post.php?id=$1&title=$2

之后,您可以使用这样的URL进行访问

https://localhost/just2minute/story/single-post/id/51835322/title/create-a-htaccess-file-with-the-code-for-clean-url

然后您要执行本文所述的操作:

https://www.tinywebhut.com/remove-duplicate-urls-from-your-website-38