【问题标题】:Hide .php extension with url rewriting using .htaccess使用 .htaccess 隐藏带有 url 重写的 .php 扩展名
【发布时间】:2012-08-31 17:10:14
【问题描述】:

我有以下网址http://www.example.com/teams.php?team_id=12 我希望这个网址是http://www.example.com/teams-pavilion-boys-varsity-soccer

我试过下面的代码

Options +FollowSymlinks    
RewriteEngine on    
RewriteRule ^teams-([0-9a-zA-Z]+)\.html$ teams.php?team_id=$1

请帮帮我。

提前致谢

【问题讨论】:

标签: php apache mod-rewrite url-rewriting


【解决方案1】:

看看这个:

http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html

我建议传递team_name 而不是team_id,或者您可以从id 中找出team_name。我什至会传递你需要的所有东西,比如“城镇”、“性别”、“等级”、“运动”

RewriteEngine on
RewriteRule ^teams-([a-zA-Z0-9_-]+)$ teams.php?team_name=$1

或者

RewriteEngine on
RewriteRule ^teams-([a-zA-Z0-9_-]+)-([a-zA-Z0-9_-]+)-([a-zA-Z0-9_-]+)-([a-zA-Z0-9_-]+)$ teams.php?team_town=$1&team_gender=$2&team_rank=$3

【讨论】:

    【解决方案2】:
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    
    RewriteCond %{REQUEST_FILENAME} -d
    
    RewriteRule .* - [L]
    
    RewriteRule ^(.*)$ [URLHERE] [NC]
    

    WATCH THIS

    【讨论】:

      猜你喜欢
      • 2013-08-13
      • 1970-01-01
      • 2012-04-19
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多