2015-07-13 188 views
3

重写动态URL后无法重定向。.htaccess动态URL重定向

动态URL:http://localhost/amploutargetsharing/campaigninfo.php?unique_hash=f5f386e

重定向后,我想要的网址看起来像下面。

所需的URL:http://localhost/amploutargetsharing/f5f386e

正如我google一下,写下面的代码。

RewriteEngine On 

RewriteCond %{REQUEST_URI} ^/amploutargetsharing/campaigninfo\.php$ 
RewriteCond %{QUERY_STRING} ^unique_hash=([a-z0-9]*)$ 
RewriteRule ^(.*)$ http://localhost/amploutargetsharing/%1 [R,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/?$ campaigninfo.php?unique_hash=$1 [L,QSA] 

而上面的代码给了我下面的结果。

HTTP //本地主机/ amploutargetsharing/f5f386e?unique_hash = f5f386e

但我想要的网址看起来像上述所需的URL。

+0

可能重复http://stackoverflow.com/questions/30591437/ htaccess-rewrite-to-remove-query-string) – CBroe

+0

是的,这是一个真正的目录Anubhava爵士 –

回答

0

/amploutargetsharing/.htaccess请尝试以下规则:

RewriteEngine On 
RewriteBase /amploutargetsharing/ 

RewriteCond %{THE_REQUEST} /campaigninfo.php\?unique_hash=([^&\s]+) [NC] 
RewriteRule^%1? [L,NE,R=302] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/?$ campaigninfo.php?unique_hash=$1 [QSA,L] 
[htaccess的重写删除查询字符串(的
+1

先生,非常感谢你的亲切帮助你的代码真的很好。:) :) –

1

试试这个:

RewriteEngine On 
RewriteCond %{THE_REQUEST} /amploutargetsharing/campaigninfo.php\?unique_hash=([^&\s]+) [NC] 
RewriteRule^amploutargetsharing/%1? [NC,R,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+)/?$ amploutargetsharing/campaigninfo.php?unique_hash=$2 [QSA,L,NC] 
+0

其不工作的兄弟.. :( –

+1

你是什么意思“它不工作”? – starkeen

+0

@Starkeen先生,代码我得到一个e 找不到对象! 在此服务器上找不到请求的URL。推荐页面上的链接似乎是错误或过时的。请通知该页面的作者关于错误。 如果您认为这是服务器错误,请与网站管理员联系。 错误404 本地主机 星期二07月14 8点43分26秒2015 阿帕奇/ 2.2.14(UNIX)DAV/2的mod_ssl/2.2.14的OpenSSL/0.9.8l PHP/5.3.1的mod_perl/2.0.4的Perl /v5.10.1 和新的URL变成这样。 http:// localhost/Applications/XAMPP/xamppfiles/htdocs/amploutargetsharing/amploutargetsharing/f5f386e –