想通过修改htaccess来隐藏网址末尾的page.html

时间:2013-04-17 08:52:52

标签: php .htaccess mod-rewrite

有人可以帮我重定向htaccess中的url。如下面的链接显示page.html到底,我想不出现,是否有可能通过更改htaccess中的任何内容,也在许多网址%显示相当多,我也想要更改为/或任何其他适当的角色。

http://www.domain.com/98-three-wheelers/listings.html
http://www.domain.com/63-we-are-currently-looking-for-customer-care-executive-for-a-call-center-in-ahmedabad/details.html
我正在使用的htaccess如下:

RewriteRule ^index.html index.php [nc]
RewriteRule ^recent_ads.html recent_ads.php [nc]
RewriteRule ^register.html register.php [nc]
RewriteRule ^pre-register.html pre-register.php [nc]
RewriteRule ^login.html login.php [nc]
RewriteRule ^logout.html logout.php [nc]
RewriteRule ^favorites.html favorites.php [nc]
RewriteRule ^contact.html contact.php [nc]
RewriteRule ^listings.html listings.php [nc]
RewriteRule ^pre-submit.html pre-submit.php [nc]
RewriteRule ^refine.html refine.php [nc]
RewriteRule ^([0-9]+)-([^\/]+)?/content.html$ content.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/index.html$ index.php?category=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/details.html$ details.php?id=$1 [nc,qsa]
RewriteRule ^([^\/]+)/([^\/]+)/([^\/]+)/recent_ads.html$ recent_ads.php?page=$1&order=$2&order_way=$3 [nc,qsa]
RewriteRule ^([^\/]+)/recent_ads.html$ recent_ads.php?page=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/user_listings.html$ user_listings.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/contact_details.html$ contact_details.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/([^\/]+)/([^\/]+)/([^\/]+)/user_listings.html$ user_listings.php?id=$1&page=$3&order=$4&order_way=$5 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)/([^\/]+)/user_listings.html$ user_listings.php?id=$1&page=$3 [nc,qsa]
RewriteRule ^([^\/]+)/([^\/]+)/([^\/]+)/favorites.html$ favorites.php?page=$1&order=$2&order_way=$3 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/store.html$ store.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/([^\/]+)/([^\/]+)/([^\/]+)/store.html$ store.php?id=$1&page=$3&order=$4&order_way=$5 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)/([^\/]+)/store.html$ store.php?id=$1&page=$3 [nc,qsa]

也可以在下面的链接中看到,在网址中使用了太多的%percenta,我可以将其更改为其他类似/不更改网址的动机,是否可以单独对htaccess进行更改以实现此目的所有?

.com/147-apartments-for-rent/no_of_rooms-1%20BHK/area_sq_ft-SQFT%20Less%20than%20500/condition_vehicles-New/listings.html

假设这一切都用于构建url

{capture name=some_content assign=constructed_url}{$live_site}/listings.php?page=1{foreach from=$post_array key=k item=x name=construct_url}{if $x!='' && $k!=$v.depending.caption2 && $k!=$v.depending.caption3 && $k!=$v.depending.caption4 && $k!="page" && $k!="show" && (!$settings.enable_locations || (!in_array($k, $location_fields) && $k!="crt_city"))}{$separator}{$k}={$x|replace:'/':'--'|urlencode}{assign var="separator" value="&"}{/if}{/foreach}{/capture}

代码中需要改变的内容..请不要介意我是编程方面的新手,刚刚开始学习这些东西....

2 个答案:

答案 0 :(得分:1)

你有这些规则

RewriteRule ^([0-9]+)-([^\/]+)?/content.html$ content.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/index.html$ index.php?category=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/details.html$ details.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/user_listings.html$ user_listings.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/contact_details.html$ contact_details.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\/]+)?/store.html$ store.php?id=$1 [nc,qsa]

当您移除content.htmlindex.htmldetails.htmluser_listings.htmlcontact_details.htmlstore.html时,您将只有

RewriteRule ^([0-9]+)-([^\/]+)?/$ ... [nc,qsa]

您如何决定,正确的要求是什么?是content.html还是index.html,也许是details.html。但它也可能是store.html

所以,我没有看到,如何删除listing.htmldetails.html等。

答案 1 :(得分:0)

当您用其他内容替换链接中的空格时,可以阻止URL中的%20。您必须查看创建网址的源代码(href=...src=...urlencode或其他一些网址创建功能)并使用str_replace例如

$url = str_replace(' ', '-', $url);
在回显<a href="$url">标记之前