.htaccess
.URLs
.I want:
demo.example.com/section.php?id=1
Changed to:
demo.example.com/section/sample-section
i tried
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^section/(\d+)*$ ./section.php?id=$1
but no difference
Thanks.
I will appreciate your help.
Create SEO Friendly URL in PHPThe generateSeoURL() function automatically creates SEO friendly URL slug from the string using PHP. A title string needs to be passed as input and it returns a human-friendly URL string with a hyphen ( - ) as the word separator. $string – Required.
URL rewriting is a technique that is often used in SEO to improve the ranking of a website. By changing the text of a website's URL, SEO experts can make it easier for web browsers to find and index the site. This can help improve the visibility of the site in search engine results pages (SERPs).
First, make sure mod_rewrite is enabled and htaccess files allowed in your Apache configuration.
Then, put this code in your htaccess (which has to be in root folder)
Options -MultiViews
RewriteEngine On
# redirect "/section.php?id=xxx" to "/section/xxx"
RewriteCond %{THE_REQUEST} \s/section\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /section/%1? [R=301,L]
# internally rewrite "/section/xxx" to "/section.php?id=xxx"
RewriteRule ^section/([0-9]+)$ /section.php?id=$1 [L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With