[英].htaccess url rewrite for single page website
我有一个单页网站,它根据使用PHP通过URL传递的变量来更改内容。
例如,我的网址显示为
www.mysite.com/index.php?section=home
www.mysite.com/index.php?section=about-us
等等,取决于您在主导航中单击的链接。
我想将网址读作www.mysite.com/home
或www.mysite.com/about-us
。
我的mod-rewrite功能已启用,因为在我创建一个单页网站之前,它运行正常。
我试过这个......
RewriteEngine on
RewriteBase /
RewriteRule ^home/?$ index.php?section=$1 [NC,L]
我已经尝试过在Google和StackOverflow上找到的所有建议,但没有任何效果。
任何帮助,将不胜感激!
几乎
RewriteEngine on
RewriteBase /
RewriteRule ^([a-zA-Z0-9-]+)/?$ index.php?section=$1 [NC,L]
我有一个.htaccess
用于完全相同的目的,它的工作非常漂亮。 我的代码如下。
RewriteEngine On
RewriteRule ^([^/\.]+)/?$ index.php?id=$1 [L]
当然,如果index.php
不是您的主要PHP文件,请将其替换为。 另外,如果您的示例代码是您正在使用的代码,请将?id
替换为?section
。
[^/\\.]+
意思是说I need you to find text that contains anything but a period (.) or a forward slash (/), and there has to be at least one character in it.
举个例子,去我在Northside Aikido上使用它的网站。
如果您有任何疑问,请随时提出。
编辑
请注意,此代码不会自动将http://www.example.com/index.php?section=home
转换为http://www.example.com/home
,这只是意味着后一个链接就像前者。 如果您希望它自动替换它,您需要的代码多于一行。
这是我使用的:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?section=$1 [NC,L]
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.