M
M
Mini MVC2016-10-16 00:48:07
htaccess
Mini MVC, 2016-10-16 00:48:07

How to change url address?

At the moment I have this url: mvc-oop/news/one/?id=1
And how to make it like this: mvc-oop/news/one/1
I tried the CNC: I have everything set up like this
AddDefaultCharset utf -8
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteRule ^([az]+)/([az]+)/([0-9]+)/$ /?ctrl=$1&act=$2 &id=$3&%{QUERY_STRING} [NS,L]
RewriteRule ^([az]+)/([az]+)/$ /?ctrl=$1&act=$2&%{QUERY_STRING} [NS,L]
RewriteRule ^ ([az]+)/([0-9]+)/$ /?ctrl=$1&id=$2&%{QUERY_STRING} [NS,L]
RewriteRule ^([az]+)/$ /?ctrl=$1 &%{QUERY_STRING} [NS,L]
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|gif)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA ]
At the mvc-oop/news/one/?id=1 address , it works for me. It displays one news item.
But when I want to go to the mvc-oop/news/one/1 address, display an error. How can I make it so that one news is displayed?
Notice: Undefined index: id in C:\OpenServer\domains\mvc-oop\www\controllers\News.php on line 23
Notice: Undefined offset: 0 in C:\OpenServer\domains\mvc-oop\www\classes\ AbstractModel.php on line 40

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2016-10-17
@shambler81

https://donatstudios.com/RewriteRule_Generator

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question