如何在每个请求的根URL之后添加一个单词?

时间:2012-09-13 06:04:12

标签: php .htaccess url-rewriting drupal-6

考虑

http://localhost/MyProject/

这是根网址

访问此内容时,我想将网址更改为

http://localhost/MyProject/Apps/

网址应如上所示,但应执行

http://localhost/MyProject/index.php

那就是我只想在网址上添加'Apps'这个词。没有名为“Apps”的文件夹...

2 个答案:

答案 0 :(得分:2)

RewriteEngine On

RewriteCond %{HTTP_HOST} ^localhost/MyProject/index/$ [NC]
RewriteRule ^(.*)$ http:localhost/index.php [R=301,L]

希望这会有所帮助......因为我没有在当地环境中尝试过。

答案 1 :(得分:1)

您的.htaccess文件(在MyProject文件夹中)需要添加Mod_Rewrite:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule /? Apps/ [R=301,L] # Force people to the "Apps" folder 
  RewriteRule Apps/?$ index.php # Make "Apps" load the index
</IfModule>