1

So I tried to rewrite an url from http://project2.local/camera?camera_id=1 to http://project2.local/camera/1 in .htaccess... Now every time I add the .htaccess lines:

Options +FollowSymlinks

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# Here we rewrite the camera link
# RewriteRule ^camera/([^/]*)$ /camera?camera_id=$1 [L]


# RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /camera\.php\?camera_id=([^\&\ ]+)
# RewriteRule ^/?camera\.php$ /camera/%1? [L,R=301]

# specific rule
RewriteCond %{QUERY_STRING} ^([^=]+)=([^&]+)
RewriteRule ^(camera)$ /camera.php?camera_id=$1 [L]

I get the error Notice: Undefined index: camera_id. Now I just try to GET the query string, but it doesn't work, like never?

What causes this issue?

1 Answer 1

1

You can use this htaccess

RewriteEngine on

#redirect and rewrite url from http://project2.local/camera?camera_id=1 to http://project2.local/camera/1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /camera\.php\?camera_id=([^\&\s]+)
RewriteRule ^/?camera\.php$ /camera/%1? [L,R=301]
RewriteRule ^camera/([^/]*)$ /camera.php?camera_id=$1 [L]
#remove. php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)/?$ $1.php [NC,L]
Sign up to request clarification or add additional context in comments.

7 Comments

That returns the same issue. On line 4, which has the following code: $camera_id = $_GET["camera_id"];
Well, if the uri /camera/1 is taking you to /camera.php this means that the RewriteRule is ok. Problem might be in your php script.
Try adding this line at the top of your htaccess Options -Multiviews .
That gives the same result, if I do a var_dump on the $_GET, it returns an empty array?
Do you have any other rules in htaccess?
|

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.