3

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 ?

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

3 Comments

If i already have a folder named blog and if i pass the value www.mywebsite.com/blog it will affect right, How can i escape from this ? (while i do RewriteCond %{blog} !-d ) still it didn't work
if i pass the value www.mywebsite.com/blog it will affect right, How can i escape from this ? Not understanding what you mean here, can you please give more detail?
If i have a folder named blog it is not working if i use www.mywebsite.com/blog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.