0

I have a URL in the form of

motors.com/project?id=1&title=british-car-auctions

And wish to change it to

motors.com/project/1/british-car-auctions

I have used solutions from URL rewriting with PHP and Rewritting URL by htaccess with no luck. As for the title section of the URL, I am calling this exact text with dashes from the database, which shouldn't be an issue. Any possible solutions to this problem?

# mode_rewrite starts here

RewriteEngine on

# does apply existing directories, meaning that if the foilder exists 

RewriteCond %{REQUESTED_FILENAME} !-d

# check for file in directory with .hmtl extension

RewriteCond %{REQUEST_FILENAME}\.php -f

# here we actually show the page that has the .html extension

RewriteRule ^(.*)$ $1.php [NC,L]

#-----------------------------------------------------

RewriteCond %{REQUESTED_FILENAME} !-d

# check for file in directory with .hmtl extension

RewriteCond %{REQUEST_FILENAME}\.html -f

# here we actually show the page that has the .html extension

RewriteRule ^(.*)$ $1.html [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^news/([0-9]+)(/?)$/([0-9a-zA-Z\s_]+) news/article.php?id=$1&title=$2 [NC,L]
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119

1 Answers1

0

Ended up finding a solution. The url rename wasn't the same as the .php file name.

So instead of:

RewriteRule ^news/([0-9]+)/([0-9a-zA-Z_-]+) article.php?id=$1&title=$2 [NC,L]

changing the php to this solved the problem:

RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+) article.php?id=$1&title=$2 [NC,L]

Also, the php code in my html had to be re-written in the same format as what I wrote on my .htaccess file

Same again, instead of:

<a class="brand-text" href="article?id=<?php echo $pizza['id']?>&title=<?php echo ($pizza['slug'])?>">

I changed it to

 <a class="brand-text" href="article/<?php echo $pizza['id']?>/<?php echo ($pizza['slug'])?>">

Hope this helps someone in the future