Apache URL Re-writing not functioning properly

前端 未结 12 1495
春和景丽
春和景丽 2021-01-17 21:31

I am trying to use apache-rewrite rule to convert the below URL:

http://localhost/foo/bar/news.php?id=24

Into this

12条回答
  •  醉话见心
    2021-01-17 22:18

    The substitution (Real) URL has a number -Code- to identify the link (According to your description): http://localhost/DIRECTORY/AID/news.php?news=42

    That code is 42 in this case, but the URL you want displayed doesn't have it. Without that number, we'll get error 404 always. It's like entering only: http://localhost/DIRECTORY/AID/news.php?news=

    Have to modify the URL you want displayed by adding the code after "/", for example. Could be a hyphen, etc., but the regex has to be modified accordingly.

    Here is an example entering: http://localhost/news/42/ to go to http://localhost/DIRECTORY/AID/news.php?news=42:

    RewriteEngine On
    RewriteRule ^news/([0-9]+)/?$ DIRECTORY/AID/news.php?news=$1 [NC,L]
    

    That's all you need. To test this example, insert this only code in news.php at http://localhost/DIRECTORY/AID/


    "; } ?>

    UPDATED according to OP description. Any name can be used instead of This_is_news:

    RewriteEngine On
    RewriteRule ^news/([0-9a-zA-Z-_]+)/?$ DIRECTORY/AID/news.php?news=$1 [NC,L]
    

提交回复
热议问题