Migrated system with new URLs

I am switching the system from MVC to the user code system. We are currently using this format for URLs:

index.php?part=CAPACITOR&type=CERAMIC&model=0805&page=spec 

I need to rewrite URLs to be more user-friendly, like

 mysitecom/CAPACITOR/ mysitecom/CAPACITOR/CERAMIC/ mysitecom/CAPACITOR/CERAMIC/0805/spec.html#2 

where # 1 and # 2 are pages loaded in jquery. The developer uses the old method using /index.php/CAPACITOR/CERAMIC/0805/spec.html

Because I don't think using index.php in the url is good, what can I do to make it better?

+6
source share
1 answer

Here you need to use

 RewriteEngine On RewriteBase / RewriteRule ^([a-z0-9\-_]+)/?$ index.php?part=$1&type=all&model=all&page=index [L,NC] RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/?$ index.php?part=$1&type=$2&model=all&page=index [L,NC] RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_]+)/?$ index.php?part=$1&type=$2&model=$3&page=index [L,NC] RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_\.]+)\.html$ index.php?part=$1&type=$2&model=$3&page=$4 [L,NC] 

Therefore, when the folder (CERAMIC example) is not specified, you can add a flag to load all, as the idea for the model. This means that if only the first part is provided, then only the first rule will be used. Starting with page.html by default, you can load the index.

Now a-z0-9\-_ means only letters, numbers, dashes and underscores ONLY. You can use ([^/]+) if you want you can use more characters.

A value of L means last , meaning that if the rule matches, it will stop. NC is not a case, so A = a or ABC = abc.

+7
source

Source: https://habr.com/ru/post/907451/


All Articles