Php Url重写困难
我想要实现的是,如果直接路径不存在,那么重写为index.php。下面是它在apache语法中的外观Php Url重写困难,php,apache,.htaccess,nginx,rewrite,Php,Apache,.htaccess,Nginx,Rewrite,我想要实现的是,如果直接路径不存在,那么重写为index.php。下面是它在apache语法中的外观 # Allow any files or directories that exist to be displayed directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Rewrite all other URLs to index.php/URL RewriteRul
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
我的nginx conf如下所示:
location / {
try_files $uri $uri/ /index.php$uri?$args;
}
但它会查找文件,如果不存在,则返回找不到的错误文件。我做错了什么?这对我很有用:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?req=$1 [L]
试试这个:
location / {
rewrite ^(.*)$ /index.php/$1;
}
您是否在使用nginx或apache时遇到问题?@RahilWazir我正试图在nginx配置中实现这一点尝试此/index.php?$query\u string;在您的target.com中,是否正确设置了根目录?我需要将其转换为nginx: