2016-08-31 40 views
1

我已阅读关于此主题的一些帖子和apache文档。htaccess:如何将网址hello/ola/ciao/register.php转换为u/u/u/page.php?

我想将网址hello/ola/ciao/page.php转换为u/u/u/page.php以隐藏网站逻辑。

如果我写:

RewriteRule ^hello/ola/ciao/(.*)$ u/u/u/$1 [R] 

RewriteRule ^hello/ola/ciao/(.*)$ u/u/u/$1 [P] 

它返回消息:

The requested URL /u/u/u/page.php was not found on this server 

MY HTTPD.CONF是:

<Directory "C:/workspace"> 
    Options Indexes FollowSymLinks 
    AllowOverride All 
    Require all granted 
</Directory> 

因此,我不希望重定向到u/u/u/page.php,因为u/u/u/文件夹在服务器上不存在。

我只想将网址转换为u/u/u/page.php,使它更好。

  • 可以得到这个结果吗?
  • 是否有可能重写url而不重定向呢?
  • 我必须使用.htaccess,RewriteRule P标志,ProxyPassReverse或PHP脚本吗?
  • 必须启用哪些apache模块?
  • 需要将.htaccess放入哪个文件夹?在根文件夹或 子文件夹呢?
  • 它可以在hoster网站或localhost上运行吗?

回答

0

尝试在根目录下这个规则

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^u/u/u/(.*).php$ hello/ola/ciao/$1.php [L] 
+0

我在浏览器地址栏中键入http://localhost/hello/ola/ciao/page.php 并没有任何反应。 我看到网页page.php – mario

+0

是否存在u/u/u/page.php? –

+0

u/u/u/page.php不存在,hello/ola/ciao/page.php存在。 如果我输入http://localhost/u/u/u/page.php我看到http://localhost/hello/ola/ciao/page.php 如果我输入http:// localhost/hello/ola/ciao/page.php我看到http://localhost/hello/ola/ciao/page.php 它可以输入http://localhost/u/u/u/page.php! 是否可以输入http://localhost/hello/ola/ciao/page.php并查看http://localhost/u/u/u/page.php? – mario