.htaccess ModReWrite 帮助

发布于 2024-07-23 07:14:11 字数 351 浏览 13 评论 0原文

我的重写代码遇到一些问题。 请注意, .htaccess 文件位于子域文件夹中 (...public_html/subdomain/ )

我只是想重写一个页面请求:

http://subdomain.mysite.com/home
http://subdomain.mysite.com/index.php?page=home

我的 .htaccess 文件看起来像这样...

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\-\_])$ /index.php?page=$1

您有什么想法吗?

I am having some trouble with my ReWrite code. Please note that the .htaccess file is in the subdomain folder (...public_html/subdomain/ )

I am simply trying to rewrite a page request:

http://subdomain.mysite.com/home
http://subdomain.mysite.com/index.php?page=home

My .htaccess file looks like this...

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\-\_])$ /index.php?page=$1

Does anything jump out at you?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铁憨憨 2024-07-30 07:14:11

您当前的规则可能适用于一个字符长的网址(斜线之后)!

添加 + 表示一个或多个字符,或添加 * 表示零个或多个

字符

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\-\_]*)$ /index.php?page=$1

Your current rule probably works for urls one character long (after the slash)!

Add a + to signify one or more characters, or a * for zero or more

Try

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\-\_]*)$ /index.php?page=$1
笙痞 2024-07-30 07:14:11

如果要在 .htaccess 文件中使用规则,则需要从 RewriteRule 模式中去除上下文每个目录路径前缀。 如果 .htaccess 文件位于文档根 / 中,则需要去掉前导 /

此外,您还需要量化字符集。 否则它只会描述一个字符。

所以尝试这个规则:

RewriteRule ^([A-Za-z0-9-_]+)$ index.php?page=$1

If you want to use the rules in a .htaccess file, you need to strip the contextual per-directory path prefix from the RewriteRule pattern. If the .htaccess file is located in the document root /, you need to strip the leading /.

Additionally you need to quantify the character set. Otherwise it would only describe one character.

So try this rule:

RewriteRule ^([A-Za-z0-9-_]+)$ index.php?page=$1
半世蒼涼 2024-07-30 07:14:11

我认为

RewriteRule ^([^/]*)$ /index.php?page=$1 [L]

还可以;)

I think

RewriteRule ^([^/]*)$ /index.php?page=$1 [L]

is ok ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文