【问题标题】:Htaccess redirect not successfully workingHtaccess 重定向未成功工作
【发布时间】:2014-12-17 22:55:18
【问题描述】:

我目前正在 localhost 中创建一个站点,但无法让重定向正常工作。我要重定向

http://localhost/s/profile.php?uid=16 

http://localhost/s/16

我怎么能这样做。我曾尝试在网上使用示例,但没有成功。

编辑:我试过了

 RewriteEngine On 
 RewriteRule ^([^/]*)\.php$ /s/profile.php?uid=$1 [L]

使用在线复制和粘贴。我总是试图弄清楚谁使用 htaccess,但似乎无法这样做。

【问题讨论】:

  • 您实际尝试过什么?发布您失败的尝试,然后我们会尽力提供帮助。
  • 我在 RewriteRule 上尝试了 RewriteEngine ^([^/]*)\.php$ /s/profile.php?uid=$1 [L]
  • 你的 htaccess 文件在哪里?
  • @JonLin 它在 s 文件夹的根目录

标签: php html .htaccess


【解决方案1】:

这是您正在寻找的基本功能。这只是一个简单的例子,你当然应该对这个主题进行研究。

或者,有很多生成器。 http://www.htaccessredirect.net/

   <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^profile\.php$ - [L,NE]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /profile.php [L,NE]
    </IfModule>

【讨论】:

    【解决方案2】:

    你可以有这个规则

    RewriteRule ^s/([^/]*)/?$ /s/profile.php?uid=$1 [L]
    

    【讨论】:

    • 你要我删除它吗?
    • 是的,用上面的规则替换你的当前规则
    【解决方案3】:

    在“s”文件夹中的 htaccess 文件中,尝试:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \ /+s/profile\.php\?uid=([^&\ ]+)
    RewriteRule ^ /s/%1.php? [L,R]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)\.php$ /s/profile.php?uid=$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2015-03-15
      • 2015-04-03
      • 1970-01-01
      • 2013-09-20
      • 2023-03-13
      • 2013-05-16
      • 2017-01-21
      • 1970-01-01
      相关资源
      最近更新 更多