Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting values in php while using `.htaccess` RewriteEngine Rule

Getting values in php while using .htaccess RewriteEngine Rule

I am using the following rule

RewriteEngine On
RewriteRule ^([^/]*)$ page.php?title=$1 [L]

It means it will create a page like view

(i.e.,)

www.mywebsite.com/contact

www.mywebsite.com/blog

But how can i get values that is passed in the url and display it inside the page using Get method echo "Page content is ".$_GET['title'];

While i pass the value in the url like www.mywebsite.com/view,

It is just displaying > Page content is page.php

What mistake i am doing and how can i fix this ?

like image 282
Explorer Avatar asked Jul 24 '26 08:07

Explorer


1 Answers

Some urls that don't need to be rewritten are getting rewritten. You probably want to change your rule like this:

RewriteEngine On
RewriteRule ^([^/.]+)/?$ page.php?title=$1 [L]
  • The [^/.] ensures that there is no dot in the path
  • The + ensures that there is at least one character
  • The /? allows an optional trailing slash
like image 131
zx81 Avatar answered Jul 26 '26 07:07

zx81



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!