Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.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 在url中使用(-)时,Apache Mod rewrite不适用于我?_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 在url中使用(-)时,Apache Mod rewrite不适用于我?

Php 在url中使用(-)时,Apache Mod rewrite不适用于我?,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,在url中使用(-)时,Apache Mod rewrite不适用于我 我试图访问第页 www.example.com/products/ipod/white-ipod-8gb/12345678 它不工作,如何编辑.htaccess文件 RewriteEngine on RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f RewriteRule ^(.*)$ $1.php [L] RewriteRule ^products/([^-]*)/([^

在url中使用(-)时,Apache Mod rewrite不适用于我

我试图访问第页

www.example.com/products/ipod/white-ipod-8gb/12345678
它不工作,如何编辑
.htaccess
文件

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^products/([^-]*)/([^-]*)/([^-]*)$ /products.php?produucts_name=$1&products_des=$2&products_id=$3 [L]
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]    
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
Options -indexes

这是因为您在正则表达式中使用了
[^-]
。使用此代码:

ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
Options -indexes
RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]    

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteRule ^products/([^/]+)/([^/]+)/([^/]*)$ /products.php?produucts_name=$1&products_des=$2&products_id=$3 [L]

-
字符在正则表达式模式中具有特殊意义。你需要像这样用反斜杠来转义它
\-