2012-01-23 36 views
1

我有一个页面名称page.php和我的网址为localhost/mysite/page.php,我现在该怎么可以用.htacess文件的URL更改为localhost/mysite/somethinghere1/somethinghere2/page.php变更网址.htacess PHP

它尝试使用下面的代码,但它不工作了。

<IfModule mod_rewrite.c> 
# Enable Rewriting 
RewriteEngine On 

# Rewrite user URLs 
# Input: user/NAME/ 
# Output: user.php?id=NAME 

RewriteRule ^somethinghere1/somethinghere2/.php? page.php 

</IfModule> 

我该如何实现这一目标。

回答

1

这个怎么样:

RewriteRule ^somethinghere1/somethinghere2/([^/\.]+).php/?$ page.php 
+0

我编辑了这个问题,我也检查你的解决方案,但它没有解决。 – Rafee

+0

@Rafee:更新了我的答案 –

+0

我得到了这个,但我需要'localhost/mysite/page.php' url更改为'localhost/mysite/something1/something2/page.php',并且我正在寻找对于。 – Rafee

0

使用方法如下:

RewriteRule ^(mysite/)somethinghere1/somethinghere2/(.*\.php)/?$ $1$2 [L,NC] 

还要确保这个在你DOCUMENT_ROOT目录中的.htaccess文件。

0
Options +FollowSymlinks 
RewriteEngine on 
RewriteRule ^([^/]+)/([^/]+)/page.php /page.php?first=$1&second=$2 [NC] 

这是基本的代码,你可以用它玩到适合像下面编辑您的需求:

Options +FollowSymlinks 
RewriteEngine on 
RewriteRule ^([^/]+)/([^/]+)/([^/]+) /$3.php?first=$1&second=$2 [NC] 

所以,X/Y/Z将z.php第一= X &?第二= y