Mod rewrite url从/example.php?id=1到页面的/example/title

Mod rewrite url从/example.php?id=1到页面的/example/title,php,url,mod-rewrite,rewrite,Php,Url,Mod Rewrite,Rewrite,我有一个生成URL的网站,如: www.site.com/example.php?id=1 我希望该url显示为: www.site.com/example/the-title-of-the-page-which-it-may-be 我可以在.htaccess中这样做吗?或者我需要编辑php还是什么 请温柔一点,把我当白痴对待-我对这一切都是全新的:)如果你使用apache服务器,你可以使用它,你确实需要一个.htaccess文件,当然还需要一些PHP代码来查看需要加载的页面。.htaccess

我有一个生成URL的网站,如:

www.site.com/example.php?id=1

我希望该url显示为:

www.site.com/example/the-title-of-the-page-which-it-may-be

我可以在.htaccess中这样做吗?或者我需要编辑php还是什么


请温柔一点,把我当白痴对待-我对这一切都是全新的:)

如果你使用apache服务器,你可以使用它,你确实需要一个.htaccess文件,当然还需要一些PHP代码来查看需要加载的页面。.htaccess可能如下所示:

# Start rewrite engine RewriteEngine On # Catch non existing files and/or folders (treat as optimized urls) RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Catch blocked folders (treat as optimized urls) RewriteRule ^(.*)$ index.php [L] #启动重写引擎 重新启动发动机 #捕获不存在的文件和/或文件夹(视为优化的URL) 重写条件%{REQUEST\u FILENAME}!\。(jpg | jpeg | gif | png | css | js | pl | txt)$ 重写cond%{REQUEST_FILENAME}-F 重写cond%{REQUEST_FILENAME}-D #捕获被阻止的文件夹(视为优化的URL) 重写规则^(.*)$index.php[L]
将此用于您的htaccess:

重新启动发动机
重写规则^([^/]*).html$/example.php?id=$1[L]

您的旧URL>example.com/example.php?id=1
将更改为>example.com/1.html

正在使用id:

重新启动发动机
重写规则^id/([^/]*).html$/example.php?id=$1[L]

您的旧URL>example.com/example.php?id=1
将更改为>example.com/id/1.html


希望能帮助你;)

您可以将apache mod_rewrite与PHP slug一起使用。谷歌搜索它,你会得到大量的解决方案。这里有一个简单的教程,可以帮助你。