URL Automatically friendly with all pages

1

I suffer from this friendly URL business, as I could do for a simple code or any code in .htaccess to make the url friendly in an automatic way without having to write all this:

    <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

  RewriteCond %{HTTP_HOST} ^5tars.com.br
  RewriteRule ^ https://www.5tars.com.br%{REQUEST_URI} [L,R=301]

  RewriteBase /

  RewriteRule ^logout/?$ /index.php?logout [NC,L]
  RewriteRule ^home/?$ /index.php?p=home [NC,L]

  RewriteRule ^recovery_pass/?$ /index.php?p=recovery_pass [NC,L]
  RewriteRule ^recovery_pass/recovery_password/?$ /index.php?p=recovery_pass&action=recovery_password [NC,L]
  RewriteRule ^recovery_pass/error_recovery_password/?$ /index.php?p=recovery_pass&action=error_recovery_password [NC,L]
  RewriteRule ^change_pass/([a-z0-9-]+)/?$ /index.php?p=change_pass&h_=$1 [NC,L]
  RewriteRule ^change_pass/([a-z0-9-]+)/password_changed/?$ /index.php?p=change_pass&h_=$1&action=password_changed [NC,L]
  RewriteRule ^change_pass/([a-z0-9-]+)/error_password_changed/?$ /index.php?p=change_pass&h_=$1&action=error_password_changed [NC,L]

  RewriteRule ^sign_in/?$ /index.php?p=sign_in&action=get-in [NC,L]
  RewriteRule ^sign_in/sign_up_success/?$ /index.php?p=sign_in&action=sign_up_success [NC,L]
  RewriteRule ^sign_in/error_sign_in/?$ /index.php?p=sign_in&action=error_sign_in [NC,L]

  RewriteRule ^sign_up/?$ /index.php?p=sign_up&action=new-user [NC,L]
  RewriteRule ^sign_up/error_sign_up/?$ /index.php?p=sign_up&action=error_sign_up [NC,L]

  RewriteRule ^user/([0-9-]+)/?$ /index.php?p=user&id=$1 [NC,L]
  RewriteRule ^user/([0-9-]+)/([0-9-]+)/?$ /index.php?p=user&id=$1&pg=$2 [NC,L]

  RewriteRule ^send_item/?$ /index.php?p=send_item [NC,L]
  RewriteRule ^send_item/suggestion_success/?$ /index.php?p=send_item&action=suggestion_success [NC,L]
  RewriteRule ^send_item/error_suggestion/?$ /index.php?p=send_item&action=error_suggestion [NC,L]

  RewriteRule ^profile/([a-z0-9-]+)/?$ /index.php?p=profile&action=$1 [NC,L]
  RewriteRule ^profile/([a-z0-9-]+)/perfil-updated/?$ /index.php?p=profile&action=$1&action=perfil-updated [NC,L]
  RewriteRule ^profile/([a-z0-9-]+)/perfil-updated-error/?$ /index.php?p=profile&action=$1&action=perfil-updated-error [NC,L]
  RewriteRule ^profile/([a-z0-9-]+)/password-updated/?$ /index.php?p=profile&action=$1&action=password-updated [NC,L]
  RewriteRule ^profile/([a-z0-9-]+)/avatar-updated/?$ /index.php?p=profile&action=$1&action=avatar-updated [NC,L]

  RewriteRule ^categories/?$ /index.php?p=categories [NC,L]

  RewriteRule ^plugin/?$ /index.php?p=plugin [NC,L]
  RewriteRule ^plugin/([0-9-]+)/?$ /index.php?p=plugin&id=$1 [NC,L]

  RewriteRule ^ranking/([0-9]+)/([a-z0-9-+-\s_]+)/?$ /index.php?p=ranking&c=$1&nome=$2 [NC,L]
  RewriteRule ^ranking/([0-9]+)/([a-z0-9-+-\s_]+)/([0-9]+)/?$ /index.php?p=ranking&c=$1&nome=$2&pg=$3 [NC,L]

  RewriteRule ^list/([0-9]+)/([a-z0-9-+-\s_]+)/?$ /index.php?p=list&c=$1&nome=$2 [NC,L]

  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/?$ /index.php?p=topic&id=$1&name=$2 [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/([0-9]+)/?$ /index.php?p=topic&id=$1&name=$2&pg=$3 [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/rates-updated/?$ /index.php?p=topic&id=$1&action=rates-updated [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/registered/?$ /index.php?p=topic&id=$1&action=registered [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/error_in_the_register/?$ /index.php?p=topic&id=$1&action=error_in_the_register [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/vote_deleted/?$ /index.php?p=topic&id=$1&action=vote_deleted [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/liked/?$ /index.php?p=topic&id=$1&action=liked [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/deleted_comment/?$ /index.php?p=topic&id=$1&action=deleted_comment [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/fail_delete_comment/?$ /index.php?p=topic&id=$1&action=fail_delete_comment [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/delete_comment/([0-9-+-]+)/?$ /index.php?p=topic&id=$1&name=$2&delete_comment=$3 [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/marked_as_spam/?$ /index.php?p=topic&id=$1&action=marked_as_spam [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/already_marked_as_spam/?$ /index.php?p=topic&id=$1&action=already_marked_as_spam [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/recent/([0-9]+)?$ /index.php?p=topic&id=$1&op_com=recent&pg=$3 [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/rating/([0-9]+)?$ /index.php?p=topic&id=$1&op_com=rating&pg=$3 [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/good/([0-9]+)?$ /index.php?p=topic&id=$1&op_com=good&pg=$3 [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/show_comment/([0-9]+)/?$ /index.php?p=topic&id=$1&name=$2&show_comment=$3 [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/show_comment/([0-9]+)/vote_deleted/?$ /index.php?p=topic&id=$1&name=$2&show_comment=$3&action=vote_deleted [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/show_comment/([0-9]+)/liked/?$ /index.php?p=topic&id=$1&name=$2&show_comment=$3&action=liked [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/error_sign_in/?$ /index.php?p=topic&id=$1&action=error_sign_in [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/error_sign_up/?$ /index.php?p=topic&id=$1&action=error_sign_up [NC,L]
  RewriteRule ^item/([0-9]+)/([a-z0-9-+-\s_]+)/sign_up_success/?$ /index.php?p=topic&id=$1&action=sign_up_success [NC,L]

  RewriteRule ^privacy_policy/?$ /index.php?p=privacy_policy [NC,L]
  RewriteRule ^terms_of_use/?$ /index.php?p=terms_of_use [NC,L]
  RewriteRule ^about/?$ /index.php?p=about [NC,L]
  RewriteRule ^about_reviews/?$ /index.php?p=about_reviews [NC,L]
  RewriteRule ^faq/?$ /index.php?p=faq [NC,L]

  RewriteRule ^admin_edit_brand/?$ /index.php?p=admin_edit_brand [NC,L]
  RewriteRule ^admin_edit_brand/([0-9]+)/?$ /index.php?p=admin_edit_brand&id=$1 [NC,L]
  RewriteRule ^admin_edit_brand/([0-9]+)/([0-9]+)/?$ /index.php?p=admin_edit_brand&id=$1&delete=$2 [NC,L]

  RewriteRule ^admin_edit_category/?$ /index.php?p=admin_edit_category [NC,L]
  RewriteRule ^admin_edit_category/([0-9]+)/?$ /index.php?p=admin_edit_category&id=$1 [NC,L]
  RewriteRule ^admin_edit_category/([0-9]+)/category_updated/?$ /index.php?p=admin_edit_category&id=$1&action=category_updated [NC,L]
  RewriteRule ^admin_edit_category/([0-9]+)/updated_error/?$ /index.php?p=admin_edit_category&id=$1&action=updated_error [NC,L]

  RewriteRule ^admin_include_brand/?$ /index.php?p=admin_include_brand [NC,L]
  RewriteRule ^admin_include_brand/register_item/?$ /index.php?p=admin_include_brand&action=register_item [NC,L]
  RewriteRule ^admin_include_brand/register_error/?$ /index.php?p=admin_include_brand&action=register_error [NC,L]

  RewriteRule ^admin_include_category/?$ /index.php?p=admin_include_category [NC,L]
  RewriteRule ^admin_include_category/register_category/?$ /index.php?p=admin_include_category&action=register_category [NC,L]
  RewriteRule ^admin_include_category/register_error/?$ /index.php?p=admin_include_category&action=register_error [NC,L]

  RewriteRule ^admin_list_categories/?$ /index.php?p=admin_list_categories [NC,L]
  RewriteRule ^admin_list_categories/([0-9]+)/?$ /index.php?p=admin_list_categories&pg=$1 [NC,L]
  RewriteRule ^admin_list_categories/([0-9]+)/([0-9]+)/?$ /index.php?p=admin_list_categories&pg=$1&delete=$2 [NC,L]

  RewriteRule ^admin_list_marks/?$ /index.php?p=admin_list_marks [NC,L]
  RewriteRule ^admin_list_marks/([0-9]+)/?$ /index.php?p=admin_list_marks&pg=$1 [NC,L]
  RewriteRule ^admin_list_marks/([0-9]+)/([0-9]+)/?$ /index.php?p=admin_list_marks&pg=$1&delete=$2 [NC,L]

  RewriteRule ^admin_list_marks/att_success/?$ /index.php?p=admin_list_marks&action=att_success [NC,L]
  RewriteRule ^admin_list_marks/error_att/?$ /index.php?p=admin_list_marks&action=error_att [NC,L]
  RewriteRule ^admin_list_marks/deleted_item/?$ /index.php?p=admin_list_marks&action=deleted_item [NC,L]
  RewriteRule ^admin_list_marks/fail_delete_item/?$ /index.php?p=admin_list_marks&action=fail_delete_item [NC,L]

  RewriteRule ^admin_list_spam/?$ /index.php?p=admin_list_spam [NC,L]
  RewriteRule ^admin_list_spam/delete_spam/([0-9]+)/?$ /index.php?p=admin_list_spam&delete=$1 [NC,L]
  RewriteRule ^admin_list_spam/delete_comment/([0-9]+)/?$ /index.php?p=admin_list_spam&delete_com=$1 [NC,L]

  RewriteRule ^admin_list_suggestion/?$ /index.php?p=admin_list_suggestion [NC,L]
  RewriteRule ^admin_list_suggestion/delete_suggestion/([0-9]+)/?$ /index.php?p=admin_list_suggestion&delete=$1 [NC,L]
</IfModule>
    
asked by anonymous 21.05.2016 / 05:18

2 answers

2

I do not know if it will help a lot, or if I understand, but I'll tell you how I use it .. my .htaccess is like this

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA]
Options -Indexes 

In php, I just do this

     $url           =$_GET['url'];
     $quebraUrl     =explode('/',$url); 
     $categoria     =$quebraUrl[0];
     $subcategoria  =$quebraUrl[1];
     $postagem      =$quebraUrl[2];

So in summary I do this:

     include("includes/$categoria.php");
    
22.05.2016 / 18:33
1

Use a library to route urls. Basically you define a url (without taking into consideration the domain name: www.domain.com), and says what should be executed when a request is made with the declared signature:

/ logout / call function or class logout

You would still have to use an .htacess file, but you would just need to redirect all requests to a specific file, index.php for example. phproute and fastroute are some of these libraries.

    
21.05.2016 / 14:46