: How to change my id and name in php url How would I change the URL from from: example.com/games.php?id=27 to: website.com/games/271/game-name-here So far I have this in .htaccess: RewriteEngine
How would I change the URL from
from: example.com/games.php?id=27
to: website.com/games/271/game-name-here
So far I have this in .htaccess:
RewriteEngine on
RewriteRule ^games/([0-9]+)/?$ games.php?id= [NC,L]
RewriteRule ^(.*).aspx$ .php
RewriteRule ^(.*).ashx$ .php
Options -Indexes
<Files 403.shtml>
order allow,deny
allow from all
</Files>
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Options -Multiviews
More posts by @Shelley277
1 Comments
Sorted by latest first Latest Oldest Best
As I understand, you want requests for the following URL website.com/games/271/game-name-here to be handled by games.php
For this, you may use a simpler rule.
RewriteRule ^games/(.*)$ /games.php?var= [L]
This will send all requests with /games/ to games.php. For e.g.
/games/271/game-name-here will go like this /games.php?var=271/game-name-here
Now, game-name-here is only for SEO purpose as what you actually need is only the id. So, filter the id part from the var like this -
$value=($_GET['var']);
$temp = explode('/',$value);
$id = $temp[0];
Remember, htaccess is used only for handling the URL requests. You still need to form the correct URLs in your webpages.
Additional Tip: You may also consider the following URL structure website.com/games/271-game-name-here . Here just explode the URL on a hyphen '-' instead of '/'
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.