简体   繁体   English

.htaccess中的3个斜杠URL重写

[英]3 Slashes in .htaccess URL rewrite

Basically I have created a PHP Website which uses API of other website to pull data . 基本上,我创建了一个PHP网站,该网站使用其他网站的API提取数据。 My problem is that I am getting Error 404 . 我的问题是我收到错误404。

I added codes below to .htaccess 我在.htaccess添加了以下代码

 RewriteRule ^sort/(.*) index.php?by=$1

this made website.com/sort/gender work ! 这使website.com/sort/gender起作用了!

But then I have another page name user.php I have added 但是然后我又添加了另一个页面名称user.php

RewriteRule ^profile/(.*) user.php?name=$1

To make website.com/profile/username 制作website.com/profile/username

But I want To Show 但我想展示

website.com/profile/username/bookmarks

Instead Of 代替

website.com/profile/username?by=bookmarks

My Full .htaccess code below : 我的完整.htaccess代码如下:

RewriteEngine on
Options +FollowSymLinks -MultiViews
RewriteBase /
ErrorDocument 404 /404.php
RewriteRule ^sort/(.*) index.php?by=$1
RewriteRule ^profile/(.*) user.php?name=$1
RewriteRule    ^privacy/?$    privacy.php    [NC,L]

You can just add another rewriterule with 2 wildcards in it like this: 您可以这样添加另一个带有2个通配符的重写器:

RewriteRule ^profile/(.*)/(.*) user.php?name=$1&by=$2
RewriteRule ^profile/(.*) user.php?name=$1

You have some missing flags and incorrect regex in your existing rewrite rules. 您现有的重写规则中有一些丢失的标志和不正确的正则表达式。

Your complete .htaccess would be like this: 您完整的.htaccess文件如下所示:

ErrorDocument 404 /404.php

RewriteEngine on
Options +FollowSymLinks -MultiViews
RewriteBase /

RewriteRule ^sort/([^/]+)/?$ index.php?by=$1 [L,NC,QSA]

RewriteRule ^(profile)/([^/]+)/([^/]+)/?$ $1/$2?by=$3 [L,NC,QSA]

RewriteRule ^profile/([^/]+)/?$ user.php?name=$1 [L,NC,QSA]

RewriteRule ^privacy/?$ privacy.php [NC,L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM