Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用.htaccess重写规则URL_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 如何使用.htaccess重写规则URL

Php 如何使用.htaccess重写规则URL,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,如何为这样的链接重写规则 http://stanime.pe.hu/content.php?idf=15&link=Katsugeki--Touken+Ranbu 到http://stanime.pe.hu/15/Katsugeki--Touken+兰布 im使用Urlencode和URLEDECODE对我的url进行编码和解码 在数据库排序中,im使用拉丁语1\u瑞典语\u ci 因此,空格将替换为+和/替换为%2f和更多 这是我的.htacces代码 RewriteEngi

如何为这样的链接重写规则

http://stanime.pe.hu/content.php?idf=15&link=Katsugeki--Touken+Ranbu
到<代码>http://stanime.pe.hu/15/Katsugeki--Touken+兰布

im使用Urlencode和URLEDECODE对我的url进行编码和解码

在数据库排序中,im使用拉丁语1\u瑞典语\u ci

因此,
空格
将替换为
+
/
替换为
%2f
和更多

这是我的.htacces代码

    RewriteEngine On

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+content\.php\?link=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ content.php?link=$1 [B,L,QSA]

您必须添加如下所示的字符规则。因为您的数据是字符形式的,而不仅仅是您在这里定义的url中的数字

  RewriteRule    ^content/([A-Za-z0-9-_]+)/?$    content.php?link=$1 [NC,L]  

首先,您需要在vhost或
http.conf
文件中添加此指令:

AllowEncodedSlashes On
这将允许在URL中使用编码的斜杠字符,即
%2F

您可以在站点根目录中使用这些规则。htaccess:

RewriteEngine On

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+content\.php\?idf=([^\s&]+)&link=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/(.+)$ content.php?idf=$1&link=$2 [B,L,QSA]

仍然找不到对象
http://localhost/web/content/Fate%2FApocrypha
重写规则^content/([0-9a-zA-Z]+)/?$content.php?link=$1[NC,L]
如果必须检查此url,那么会发生什么?只为url工作,没有空格或特殊字符。。当我尝试打开错误显示时,您可以自己尝试好的,为什么要在url中添加空间?您可以删除链接中创建url之前的空间。为此,您可以使用str_replace funtionhahaha,我使用本机php创建我的网站,我不知道如何路由正确的URL,URL生成基于标题,因为我使用免费托管我无法访问apache文件。还有其他方法吗?不幸的是,
allowencodedslass
只允许在Apache config.haha中使用,很遗憾听到这个消息。。。我试着在我的专用文件中查找httpd.conf,但在/etc/apache2中找不到,没有名为httpd.confi的文件。当我有相同的标题时,我发现一个错误,然后我修改了我的链接,使之像这样<代码>http://stanime.pe.hu/content.php?idf=15&link=Katsugeki--Touken+Ranbu我希望链接将是这样的
http://stanime.pe.hu//15/Katsugeki--Touken+Ranbu
Ah但这是一个不同的URL,因为您现在有两个查询参数。