使用htaccess缩短网址问题

时间:2011-08-10 06:07:41

标签: php .htaccess

我需要改变

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

http://localhost/engineering/course_view.php

使用htaccess

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

为此工作正常,

但是对于以下网址,它不起作用

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

2 个答案:

答案 0 :(得分:0)

请尝试使用此代码: -

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

希望它有所帮助。

答案 1 :(得分:0)

当你使用这个时!

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

因为它可以重写其他URL(你已经提到过),你可以添加特殊部分来避免这种情况。 e.g:

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

和网址:

http://localhost/engineering/swdcourse_view.php

并且对于第二个,使用除swd之外的其他字符!!

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