【问题标题】:how to create friendly url in my directory using php如何使用 php 在我的目录中创建友好的 url
【发布时间】:2013-09-06 13:14:28
【问题描述】:

我使用这些类型的 URL:

http://test.com/rest/api.php?action=test

但我需要这些类型的 URL:

http://test.com/rest/api/action/test

我尝试在此处.htaccess 归档这些代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]

【问题讨论】:

    标签: .htaccess url-rewriting seo


    【解决方案1】:

    通过将您的代码替换为 .htaccessDOCUMENT_ROOT/rest 目录下来放置此代码:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /rest/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^api/([^/]+)/?$ api.php?action=$1 [QSA,NC,L]
    

    【讨论】:

      【解决方案2】:

      这应该可以解决它:

      RewriteEngine On
      RewriteRule ^rest/api.php?action=test$ /rest/api/action/test [L]
      

      【讨论】:

      • RewriteRule 与查询字符串不匹配。
      【解决方案3】:

      您的目标可以通过使用语法如下的正则表达式来实现:

      RewriteRule ^rest/api/action/(\d+)*$ ./rest/api.php?action=$1 
      

      尝试阅读这些文章:

      http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-02
        • 2016-06-02
        • 2011-03-25
        相关资源
        最近更新 更多