简体   繁体   中英

Shortening URL using .htaccess

My folder structure is:

modules

  • admin

    • index.php
  • login

    • login.php
    • signup.php
  • articles

    • articles.php

My current URL is:

localhost/modules/admin/index.php

localhost/modules/login/login.php

localhost/modules/articles/articles.php

I want to change it to:

localhost/index

localhost/login

localhost/articles

Since ia beginner in using .htaccess file, pls help me how i can change the URL using .htaccess file

Your folder structure makes it difficult to have a universal rule but you should be able to use these rules.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(index)/?$ /modules/admin/$1.php [NC,L,QSA]
RewriteRule ^(login|articles)/?$ /modules/$1/$1.php [NC,L,QSA]

Try this

Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteRule ^index([^/]*) /admin/index.php [L]
RewriteRule ^login([^/]*) /login/login.php [L]
RewriteRule ^signup([^/]*) /login/signup.php [L]
RewriteRule ^articles([^/]*) /articles/articles.php [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM