Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
Apache .htaccess重写规则问题_Apache_.htaccess_Mod Rewrite_Codeigniter 2_Codeigniter Url - Fatal编程技术网

Apache .htaccess重写规则问题

Apache .htaccess重写规则问题,apache,.htaccess,mod-rewrite,codeigniter-2,codeigniter-url,Apache,.htaccess,Mod Rewrite,Codeigniter 2,Codeigniter Url,我正在尝试使用mod_rewrite重写一些URL 我想重写 localhost/exotica/pet/somePet/ 到 我通过使用 RewriteCond $1 !^(index\.php|resources|uploads|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /exotica/index.php/$1 [L]

我正在尝试使用mod_rewrite重写一些URL

我想重写

localhost/exotica/pet/somePet/

我通过使用

RewriteCond $1 !^(index\.php|resources|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /exotica/index.php/$1 [L]
所以现在
localhost/exotica/types/get/somePet
起作用了 我试着把添加作为第一条规则

RewriteRule ^pet/([A-Za-z0-9-]+)/?$ type/get/$1 [N]
但它根本不工作,所以请帮助我,我不知道如何启用它


我通过添加一个route
$route['pet/(:any)]=“type/get/$1”来解决这个问题,但我更喜欢使用.htacess文件执行此操作

请按相反顺序尝试以下规则:

RewriteEngine On
RewriteBase /exotica/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pet/([A-Za-z0-9-]+)/?$ types/get/$1 [L]

RewriteCond $1 !^(index\.php|resources|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

/exotica/pet/somePet/
(传入的SEO格式)转到
/exotica/index.php/types/get/somePet/
是胡说八道。充其量,你仍然需要重写成“动态”格式,比如
/exotica/index.php?types=xxxxx&op=get&name=somePet
,你也可以“提前”完成它。@anubhava没问题没有解决,因为我想用mod rewrite而不是codeigniter rutes来完成它。@PhilPerry我真的不明白你的意思。你建议我用第三种吗?第二种类型的url是codeigniter使用的,第一种类型的url是我想要使用的,需要重写为第二种类型。真的不知道第二个是否被CodeIgniter内部重写为第三个。上面的.htaccess文件的位置是什么?是在
DocumentRoot
还是
DocumentRoot/exotica
?我想说的是,您最终必须使用
/index.php?var1=value1&var2=value2
等格式,服务器和php才能处理它。将一种SEO格式转换为另一种SEO格式不会让你有任何进展。我认为可以将SEO1转换为SEO2,然后将SEO2转换为动态(非SEO)格式,但如果您是从零开始的,那么最好一步完成。通常这都是在.htaccess中完成的——codeigniter是在内部完成的吗?
RewriteEngine On
RewriteBase /exotica/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pet/([A-Za-z0-9-]+)/?$ types/get/$1 [L]

RewriteCond $1 !^(index\.php|resources|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]