【发布时间】:2012-08-23 11:24:51
【问题描述】:
好吧,标题真的很草率。
这是我的问题:我有一个新闻站点,当您转到主页 (domain.com) 时,它会在确定您的地理位置后将您重定向到 domain.com/news/top?geography=San_Francisco。
如何使用 .htaccess 以使其来自 domain.com/news/top?geography=San_Francisco domain.com/San_Francisco/news/top ?
有一些类似的问题,但我没有找到一个足够相似的问题,因为您正在将 URL 编辑为更靠后的子目录。
还应该注意的是,我正在使用 PHP 的 Code Igniter 框架,它通常具有 domain.com/index.php/news/top?geography=San_Francisco 但我已经做了一个 mod_rewrite 以摆脱 index.php。代码如下:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
我试过的代码:
RewriteRule ^([^/]+)/news/top$ /news/top?geography=$1 [L,QSA]
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
【问题讨论】:
标签: .htaccess codeigniter mod-rewrite url-rewriting