Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8740191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:05:17+00:00 2026-06-13T11:05:17+00:00

Possible Duplicate: Regular Expression Sanitize (PHP) I want to make my links SEO. Before

  • 0

Possible Duplicate:
Regular Expression Sanitize (PHP)

I want to make my links SEO. Before I started the links looked like this:

http://www.domain.tld/index.php?page=blog

My goal was to change it to: http://www.domain.tld/blog. That works now.

I changed the htaccess to this:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\w+$ index.php?page=$0 [L]
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{QUERY_STRING} ^page=(\w+)$
RewriteRule ^index\.php$ /%1? [R=301,L]
RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2

Now I want to change the URIs of the headlines of any blog entry. They looked like this: http://www.domain.tld/index.php?page=single_news&id=2&headline=This%20Is%20A%20Headline

I want to make them looking like this: http://www.domain.tld/blog/2-this-is-a-headline
I am generating my headline-links in the div-class “news_headline” (see below).

<div id="main">
<?php
$query = "SELECT `id`, `headline`, `writer`, `content`, DATE_FORMAT(date,\"%d. %M %Y\") AS `date` FROM `blog` ORDER BY `id` DESC";
$news_resource = mysql_query($query) or die(mysql_error());
?>

<?php
$all_news = array();
$five_news = array();
for($i = 0; $news = mysql_fetch_object($news_resource); $i++){
if($i < 5){
  $five_news[] = $news;
}
$all_news[] = $news;
}
?>

<?php foreach($five_news as $news)
{ ?>

<div class="news_bg">
<div class="news_headline"><a href="blog/<?php echo $news->id; ?>-<?php echo $news->headline; ?>"><?php echo $news->headline; ?></a></div>
<div class="news_infoline_top"><?php echo $news->date; ?> &middot; <?php echo $news->writer; ?></div>
<div class="news_text"><?php echo $news->content; ?></div>
</div>
<?php } ?>
</div>

With my htaccess (see above) the links are like this now:

http://www.domain.tld/blog/2-This Is A Headline

I already had help about this and a good guy gave me this code-snippets to make the links looking like I want, but I don’t know how to use them:

$urititle = strtolower(preg_replace('/[^\w-]+/','-', $title));

and

$_GET['headline'] != $urititle

I am lost.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:05:18+00:00Added an answer on June 13, 2026 at 11:05 am

    You are already pretty close:

    • You put the ID to the beginning of the intersting part. That allows you to query your database by the ID which is unique and fast.
    • You have the understanding that you need to transform the text of the headline into the slug variant of it and you already know that this is string processing.

    You have some steps left to finish this. Somme notes:

    • Create yourself a function that does the string transformation. The important part here is, that you can call it simply.
    • When the request to an article comes in, fetch the article based on the ID value you obtain from the string: $assigned = sscanf($slug, '%d-', $id);
    • For SEO, do the same as when creating the link. Then compare if the current link still is correct (the headline might have changed). If not, do a permanent redirect to the correct link.

    And that’s it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php regular expression help? hi, i want to replace i like apple
Possible Duplicate: Useful Regular Expression Tutorial Hello, I recently started coding in javascript. I
Possible Duplicate: Sanitization of User-Supplied Regular Expressions in PHP Let's say you want to
Possible Duplicate: regular expression for letters, numbers and - _ I would like to
Possible Duplicate: How do you pass a variable to a Regular Expression JavaScript? This
Possible Duplicate: What is the best regular expression for validating email addresses? I want
Possible Duplicate: What is a regular expression for a MAC Address? I would like
Possible Duplicate: How exactly do Regular Expression word boundaries work in PHP? How can
Possible Duplicate: Python Regular Expression Matching: ## ## I already asked this question, but
Possible Duplicate: How do I make part of a regular expression optional in Ruby?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.