重定向不改变网址不改变、重定向、网址

2023-09-02 11:25:48 作者:星夜游魂

我一直吮吸的.htaccess 我想有一个网站,所有的请求,虽然去的index.php,但我希望能像www.sample.com/home的URL。有效的URL会加载www.sample.com/index.php?page=home

I always suck at .htaccess I'm trying to have a website where all requests go though index.php but i'd like the URL to be like www.sample.com/home. effectively that url would load www.sample.com/index.php?page=home

现在我有

 RewriteRule ^/([a-z0-9-]+) /index.php?page=$1 [NC,PT,L]

这不工作,即使regexr测试显示它应该。我暂时改成了R = 301,所以我能看到的重定向,发现www.sample.com/home被重定向到www.sample.com/index.php?page=/index.php~~V:(

Which doesnt work even though regexr test shows it should. I temporarily changed it to r=301 so i could see the redirect and noticed that www.sample.com/home is redirecting to www.sample.com/index.php?page=/index.php :(

有什么想法?

请注意我一直在寻找这一段时间,我无法找到一个解决方案,实际工作。它不喜欢,这是我的第一站。

Note I've been searching for this for a while and I can't find a solution that actually works. It's not like this was my first stop.

推荐答案

更​​改您的规则:

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s/+index.php?page=([^s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]

RewriteRule ^([a-z0-9-]+)/?$ /index.php?page=$1 [QSA,L,NC]