简体   繁体   English

使用.htaccess将查询字符串传递到URL

[英]passing a query string to URL using .htaccess

I am trying to add the page title into the URL. 我正在尝试将页面标题添加到URL中。 Just like this site does! 就像这个网站一样! Basically I want to rewrite the url from 基本上我想从重写URL

    www.siteurl.co.uk/project-82

to

    www.siteurl.co.uk/project/the-title-of-the-project

The string that is passed from the php to html file is {PROJECT_TITLE}. 从php传递到html文件的字符串是{PROJECT_TITLE}。 How would I add this in the .htaccess file? 如何将其添加到.htaccess文件中? Thanks guys! 多谢你们!

EDIT: 编辑:

This is my .htaccess file 这是我的.htaccess文件

    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /project\.php [NC]
    RewriteCond %{QUERY_STRING} id=([0-9]+) [NC]
    RewriteRule . project-%1? [R=301]
RewriteEngine On
RewriteRule ^project/([a-z-]+)/?$ index.php?project_title=$1

With the above .htaccess , when accessing 使用上面的.htaccess进行访问时

www.siteurl.co.uk/project/the-title-of-the-project www.siteurl.co.uk/project/the-title-of-the-project

You will in your PHP script have a variable $_GET['project_title'] containing "the-title-of-the-project". 您将在您的PHP脚本中具有一个变量$_GET['project_title']其中包含“ the-title-of-the-project”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM