htaccess 需要帮助重写 url [英] htaccess need help rewriting url
问题描述
我一直在尝试用 htaccess 文件重写我的 URL.我的项目使用我的 index.php 作为它的基本控制器.我使用获取值naam"从数据库中获取页面.
I've been trying to rewrite my URL's with a htaccess file. My project is using my index.php as it's basic controller. I fetch the pages from the database with the get-value "naam".
示例:localhost/YourDesigns/YDCMS/index.php?naam=home(显示主页)localhost/YourDesigns/YDCMS/index.php?naam=about(显示关于页面)
Example: localhost/YourDesigns/YDCMS/index.php?naam=home (this shows the homepage) localhost/YourDesigns/YDCMS/index.php?naam=about (this shows the about page)
现在我想重写 URLS 以显示如下:localhost/YourDesigns/YDCMS/home(显示主页)localhost/YourDesigns/YDCMS/about(显示关于页面)
Now i want to rewrite the URLS to be shown like this: localhost/YourDesigns/YDCMS/home (this shows the homepage) localhost/YourDesigns/YDCMS/about (this shows the about page)
我自己做了一些 htaccess 的东西,我已经成功地从 url 中删除了index.php",但naam"仍然存在.
I have done some htaccess stuff myself and i've successfully removed the "index.php" from the url, but the "naam" still remains.
我如何删除它?这是我当前的 htaccess 文件:
How do i remove this? This is my current htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /YourDesigns/YDCMS/index.php?naam=/$1 [L]
提前致谢:)
推荐答案
我觉得你看流程的方式不太对,如果你想像你说的那样显示 url localhost/YourDesigns/YDCMS/home
您必须首先将 html 内容中的 url 替换为该格式,然后使用 RewriteRule 在内部调用正确的路径:
I think your way to see the process it's not totally right, if you want to show the url like you say localhost/YourDesigns/YDCMS/home
you have to first replace the url inside your html content to that format, then by using a RewriteRule you call the correct path internally:
RewriteRule ^desired_url_path/([a-z0-9\-]+)$ /base_url_path/index.php?naam=$1 [L]
这样当用户点击一个链接时,Apache 服务器将使用上面的正则表达式来转换 url,规则基本上是:基本 url 之后的所有内容都是要传递到 index.php 的参数值.当然,正则表达式可以根据您的需要进行修改,我上面写的那个是一个基本的字符串模式.
this way when an user click on a link the Apache server will use the above regex to convert the url by a rule that basically says : everything after the base url is aparameter value to be passed on the index.php. Naturally the regex can be modified to suit your needs, the one i've written above it's a basic string pattern.
这篇关于htaccess 需要帮助重写 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!