Apache 如何重写我的url?

Apache 如何重写我的url?,apache,.htaccess,url-rewriting,Apache,.htaccess,Url Rewriting,嘿 我正在开发一个网站,在.htaccess方面有一个小问题 问题: 如何重写URL From: http://www.mysite.com/index.php?page=about To: http://www.mysite.com/about/ 及 及 目前我正在这样做,但不起作用!:( 选项+FollowSymlinks 重新启动发动机 重写规则^page/([^/\.]+)/?$index.php?page=$1[L] 重写规则^page/([^/]+)/([^/]+)/?$i

我正在开发一个网站,在
.htaccess
方面有一个小问题

问题: 如何重写URL

From: http://www.mysite.com/index.php?page=about 
To:   http://www.mysite.com/about/

目前我正在这样做,但不起作用!:(


选项+FollowSymlinks
重新启动发动机
重写规则^page/([^/\.]+)/?$index.php?page=$1[L]
重写规则^page/([^/]+)/([^/]+)/?$index.php?page=$1&catId=$2[L]
请帮忙。
提前感谢,Silvano。

您当前拥有的
。htaccess
文件与您的重写请求无关

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?page=$1&catId=$2 [L]
以下是您需要的:

第一:

RewriteRule ^(.*)/$ index.php?page=$1
第二点:

RewriteRule ^(.*)/([0-9]*)$ index.php?page=$1&catId=$2
确保在顶部添加
RewriteEngine on


您的服务器将永远无法获取url中的“#someAnchor”部分,因为世界上没有浏览器会将此作为请求的一部分发送。浏览器会将其保持为私有状态。

这将满足您的要求:

#Rewrite /about/ to /index.php?page=about
RewriteRule ^([0-9a-z]+)/?$ index.php?page=$1 [NC,L]

#/stuff/1/ to /index.php?page=stuff&catId=1
RewriteRule ^([0-9a-z]+)/([0-9]+)/?$ index.php?page=$1&catId=$2 [NC,L]

#/stuff/1/#someAnchor to /index.php?page=stuff&catId=1#someAnchor   
RewriteRule ^([0-9a-z]+)/([0-9]+)/(#[0-9a-z]+)?$ index.php?page=$1&catId=$2$3 [NC,L]

可以在我的本地服务器(WAMP)上运行。

为什么不在PHP脚本中包含这些内容呢?您可以在请求特定页面时重定向。因为它对搜索引擎更友好。您在httpd.conf中是否有以下行?LoadModule rewrite\u module modules/mod\u rewrite.so抱歉,它不起作用。我有一个“内部服务器错误”.还有其他想法吗?致以最良好的祝愿。对不起。我的不好。我的.htacss中有一些未知字符。谢谢,致以最良好的祝愿。
RewriteRule ^(.*)/$ index.php?page=$1
RewriteRule ^(.*)/([0-9]*)$ index.php?page=$1&catId=$2
#Rewrite /about/ to /index.php?page=about
RewriteRule ^([0-9a-z]+)/?$ index.php?page=$1 [NC,L]

#/stuff/1/ to /index.php?page=stuff&catId=1
RewriteRule ^([0-9a-z]+)/([0-9]+)/?$ index.php?page=$1&catId=$2 [NC,L]

#/stuff/1/#someAnchor to /index.php?page=stuff&catId=1#someAnchor   
RewriteRule ^([0-9a-z]+)/([0-9]+)/(#[0-9a-z]+)?$ index.php?page=$1&catId=$2$3 [NC,L]