1

I am trying to add the page title into the URL. Just like this site does! Basically I want to rewrite the url from

    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}. How would I add this in the .htaccess file? Thanks guys!

EDIT:

This is my .htaccess file

    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]
0

1 Answer 1

1
RewriteEngine On
RewriteRule ^project/([a-z-]+)/?$ index.php?project_title=$1

With the above .htaccess, when accessing

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".

Sign up to request clarification or add additional context in comments.

11 Comments

Thanks for the quick reply! I meant change it to www.siteurl.co.uk/project/the-title-of-the-project
Also in the php I have $page->SetParameter ('PROJECT_TITLE', $project_title); but not &_GET['project_title']. Will that still work?
Since I don't have your source code, I can't tell you if it'll work. But if you use $page->SetParameter ('PROJECT_TITLE', $_GET['project_title'], then it probably will. I have updated my answer.
Hi, Just tried that but with no luck. It has been playing up all day! I have edited my post with the .htaccess code i currently have.
You have not edited your post with your .htaccess, but that doesn't matter. $page->SetParameter() is not standard PHP functionality, so I have no idea what it does.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.