Apache的htaccess的地图第一段为参数,而不会干扰其他参数 [英] apache htaccess map first segment as parameter without disturbing other parameters

查看:194
本文介绍了Apache的htaccess的地图第一段为参数,而不会干扰其他参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是可能是一个经典的.htaccess的问题,但我仍然无法找到我的具体情况的问题。下面是href="http://stackoverflow.com/questions/9299793/apache-httaccess-rewriting">最接近我发现(参数包括在我的情况)的

我的情况下

1)我想任何访问这个URL,

  mywebsite.com/any-first-segment?param1=a&param2=b&param3=c&paramN=anything
 

将被重新映射到

<$p$p><$c$c>mywebsite.com/index.php?p=any-first-segment&param1=a&param2=b&param3=c&paramN=anything

2)静态工作,如果没有参数。

3)我永远不会有一个以上的段。 (零段仍然有效,映射到index.php像往常一样)


您可以建议我的工作重写规则对于这种情况?

下面是最后的.htaccess,这仍无法正常工作

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-l
重写规则^(。+)$的index.php?P = $ 1 [QSA,L]
 


[更新!] 它的工作。我发现我搞砸了选项+了FollowSymLinks 看完后<一href="http://stackoverflow.com/questions/3829877/htaccess-$c$c-to-set-qsa-for-all-redirects-automatically-globally">this

这里是工作的.htaccess。随着例外。

  RewriteEngine叙述上
的RewriteCond $ l ^(指数\ .PHP |图片|机器人\ .TXT | CSS)!
重写规则^(。+)$的index.php?P = $ 1 [QSA,L]
 

解决方案

使用的 QSA 标志在你的规则将追加当前查询字符串重写形式。

This is might be a classic .htaccess question, but still I couldn't find the question for my specific case. Here's the closest I found (parameters involve in my case). Done implementing the two answers. Couldn't work for my case.

My case

1) I want any access for this URL,

mywebsite.com/any-first-segment?param1=a&param2=b&param3=c&paramN=anything

will be remapped to

mywebsite.com/index.php?p=any-first-segment&param1=a&param2=b&param3=c&paramN=anything

2) Still working if there's no param.

3) I will never have more than one segment. (zero segment still works, mapped to index.php as usual)


Could you suggest me the working RewriteRule for this case?

Here's the last .htaccess, which is still not working

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?p=$1 [QSA,L]


[Updated!] It's working. I found I messed up with Options +FollowSymLinks after reading this

Here's the working .htaccess. With exception.

RewriteEngine On
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.+)$ index.php?p=$1 [QSA,L]

解决方案

Using the QSA flag in your rule will append the current query string to the rewritten form.

这篇关于Apache的htaccess的地图第一段为参数,而不会干扰其他参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆