URL Rewrite.htaccess

I am going to develop a website with the following URL structure.

I am new to rewriting URLs and would like to know how to best deal with this.

http://domain.com index.php http://domain.com/about about.php http://domain.com/agencies agencies.php http://domain.com/contact contact.php http://domain.com/publisher publisher.php http://domain.com/publisher/sign_up publisher_signup.php http://domain.com/agencies/sign_up agencies_signup.php http://domain.com/agencies/login login.php http://domain.com/advertiser advertiser.php http://domain.com/advertiser/sign_up advertiser_signup.php http://domain.com/advertiser/login login.php 

What would be the most efficient rewriting htaccess?

Should I just manually enter each line with rewriting, or is there a good search / replace that I could use?

I think that in the long run the number of slashes in the URL may be the largest, for example

  http://domain.com/area/sub_area/sub_area2/sub_area3 

Any help would be greatly appreciated.

+4
source share
1 answer

Sorry, but your "URL" conversion is not homogeneous (= impossible to "generalize" because they do not share the same principles exactly ), so best of all I could do:

 RewriteEngine On ^/?$ index.php [NC,QSA,L] ^/?about$ about.php [NC,QSA,L] ^/?(agencies|contact|publisher|advertiser)$ /$1.php [NC,QSA,L] ^/?(publisher|agencies|advertiser)/sign_up$ /$1_signup.php [NC,QSA,L] ^/?(publisher|agencies|advertiser)/login$ /login.php [NC,QSA,L] 

But if you want “homogeneous” things that don't match your needs, you can have “cleaner” rules, for example:

 RewriteEngine On ^/?$ index.php [NC,QSA,L] ^/?about$ about.php [NC,QSA,L] ^/?(agencies|contact|publisher|advertiser)$ /$1.php [NC,QSA,L] ^/?(agencies|contact|publisher|advertiser)/sign_up$ /$1_signup.php [NC,QSA,L] ^/?(agencies|contact|publisher|advertiser)/login$ /login.php [NC,QSA,L] 

And if you really want to centralize everything, you can do (= pass the type to the php file):

 RewriteEngine On ^/?$ index.php [NC,QSA,L] ^/?about$ about.php [NC,QSA,L] ^/?(agencies|contact|publisher|advertiser)$ /$1.php [NC,QSA,L] ^/?(agencies|contact|publisher|advertiser)/(sign_up|login)$ /$2.php?type=$1 [NC,QSA,L] 
+2
source

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


All Articles