2017-06-04 54 views
1

我需要重写此:使用文字斜杠作为参数之后 - htaccess的

http://example.com/new/location/ 

到:

http://example.com/new.php?p=location 

顺便说一下它可能后新是什么/例如,我需要:

http://example.com/new/anything 

实际上是:

http://example.com/new.php?p=anything 

但我需要保持URL结构与斜线的搜索引擎优化和安全的目的

我怎么能做到这一点使用的.htaccess?

在我的htaccess的香港专业教育学院目前

有:

RewriteEngine on 
RewriteBase /dir/ 

感谢

+0

[Apache的可能重复重写规则URL参数](https://stackoverflow.com/questions/9754787/apache-rewriterule-with-url-parameters) – rickdenhaan

回答

0

将以下指令添加到您的.htaccess:

RewriteRule ^new/location$ new.php?p=location [L] 

或工作的任何值使用:

RewriteRule ^new/(.*)$ new.php?p=$1 [L] 
+0

字的位置可能是其他任何东西,我怎么能让它更动态如果让我们说这个网址是新的/地址这将是new.php?p =地址 – Kobi

+0

然后只需用$ 1替换单词位置 - 这意味着可能有任何东西。 RewriteRule^new /(.*)$ new.php?p = $ 1 [L] – BDS

+0

你是男人! – Kobi