Rewrite URL in PHP with mod_rewrite

前端 未结 3 975
夕颜
夕颜 2021-01-28 16:01

The web server is Apache. I want to rewrite URL so a user won\'t know the actual directory. For example: The original URL:

http://www.example.com         


        
相关标签:
3条回答
  • 2021-01-28 16:28

    You need to define a rewrite rule (should be similar to this):

    RewriteRule ^/(.*)/en/piecework/(.*)piecework_id=([0-9]+)(.*) piecework.mydomainname.com/en/$3
    

    and put it in a .htaccess file under the main folder of you site

    Full description of Rewrite rules here: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

    EDIT

    Made a mistake in my rule, hopefully I corrected it.

    0 讨论(0)
  • 2021-01-28 16:29

    I would suggest the following rule:

    RewriteCond %{HTTP_HOST} ^(?!www)([^.]+)\.mydomainname\.com$ [NC]
    RewriteRule ^(w+)/(\d+)$ /$1/%1/%1.php?%1_id=$2 [L]
    
    0 讨论(0)
  • 2021-01-28 16:35

    I found a fairly well written crash course in doing so here:
    http://articles.sitepoint.com/article/guide-url-rewriting

    You'll need to specify the rules in .htaccess (in your site root).

    0 讨论(0)
提交回复
热议问题