2011-12-12 78 views
1

我查看了类似的问题,但它与我的具体示例无关。如何使用变量掩码URL(.htaccess)

1 URL(什么是要发送到服务器和最初输入到地址栏):www.site.com/?variable1=3 &变量2 = filename.php

第二URL(是什么在URL栏中显示给用户):www.site.com/filename.php

其中“filename.php”与原始URL中的“variable2”的值相同。

我见过the opposite的例子,其中有人输入第二个URL并用第一个URL代替它,但那不是我想要的。

目前我有:

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/
RewriteRule ^/([A-Za-z0-9]+)$ /?CommID=$1&FileName=$2 [NC,L] 

,我得到了来自this question提供的链接结构,但不工作。

我不想重定向,只是掩盖当前的URL,所以它是搜索引擎优化友好。我需要抓取URL中的两个变量才能正确拉取动态内容。

任何想法?

+0

我只看到变量2中第二个网址:哪里是变量1? –

+0

变量1没有必要位于第二个URL中,但是如果它唯一可行的方法是获取它,则可以将其添加进去。 – Oneag

回答

1

尝试增加您的域的根目录下,以您的.htaccess文件

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/

#if the query string has a commid and a fIlename Param 
RewriteCond %{QUERY_STRING} ^CommID=([^&]+)&FileName=([^&]+) [NC] 
#redirect users to the Pretty URL of www.site.com/variable1/filename.php 
RewriteRule .* /%1/%2? [L,R=301] 

#for a URL like this in address bar www.site.com/variable1/filename.php 
#CommID will contain variable1 and FileName will contain filename.php 
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9\.]+)$ /?CommID=$1&FileName=$2 [NC,L] 

编辑: 还使用重定向的查询字符串URL的用户漂亮的URL

+0

URL仍显示www.thesite.com/?CommID=3&FileName=about- us.php。 – Oneag

+0

查看我上面的编辑 –

+0

它非常接近!它会正确重定向到漂亮的URL,但会在浏览器中引发重定向循环错误。 这个URL是它提供的:www.thesite.com/3/about-us.php?CommID=3&FileName=about-us.php – Oneag