简体   繁体   中英

shorten url problem using htaccess

I need to change

http://localhost/engineering/management/administrator/modules/course/view.php

to

http://localhost/engineering/course_view.php

using htaccess

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)_(.*)\.php$   management/administrator/modules/$1/$2.php
RewriteRule ^(.*)_(.*)\.php$   management/user/modules/$1/$2.php

Works fine for this,

But for the below url its not working

http://localhost/engineering/management/user/modules/data/edit.php

Please try with this code:-

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)_(.*)\.php$ management/administrator/modules/$1/$2.php
RewriteRule ^(.*)_(.*)\.php$ management/user/modules/$1/$2.php

Hope it helps.

when you use this one!

RewriteRule   (.*)_(.*)\.php  management/administrator/modules/$1/$2.php

because it's possile ro rewrite other URLs(that you've mentioned), you can add special part to it to avoid such thing. eg:

RewriteRule   swd(.*)_(.*)\.php  management/administrator/modules/$1/$2.php

and url:

http://localhost/engineering/swdcourse_view.php

and for second one, use other characters than swd !!

RewriteRule   ^usr(.*)_(.*)\.php$  management/user/modules/$1/$2.php

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