简体   繁体   English

带有许多变量的mod_rewrite URL

[英]mod_rewrite URL with many variables

I'm new to mod-rewrite and I have tried to mod-rewrite this url with no success. 我是mod重写的新手,但我尝试对该URL进行mod重写没有成功。

URL structure like this : 网址结构如下:

http://mysite.com/script.php?id=15751890&xp=862297&wm=1721&ls=2725&he=63530&ks=23050&eath=53588&tk=10&ck=john&rk=37

I want to mod-rewrite it to : 我想对其进行mod-rewrite:

http://mysite.com/script.php?id=15751890

Or : 要么 :

http://mysite.com/15751890/862297/1721/2725/63530/23050/53588/10/john/37

I followed this http://wettone.com/code/clean-urls and this http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/ 我遵循了这个http://wettone.com/code/clean-urls和这个http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/

But just can't do it write 但是写不出来

What to type in htaccess file 在htaccess文件中输入什么

Well, if you really want to write such a rewrite you should be able to use this in your htaccess file. 好吧,如果您真的想编写这样的重写,您应该可以在htaccess文件中使用它。 There are probably better ways to handle the URL's however, I'm giving you what you asked for. 可能有更好的方法来处理URL,但是,我正在为您提供您所要求的。

NOTE: I'm going off of the URL you provided. 注意:我不使用您提供的URL。

RewriteEngine on
RewriteRule (.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*) script.php?id=$1&xp=$2&wm=$3&ls=$4&he=$5&ks=$6&eath=$7&tk=$8&ck=$9&rk=$10&%{QUERY_STRING}$ [L]

So you can use this type of URL with that rewrite. 因此,您可以在重写时使用这种类型的URL。

http://mysite.com/15751890/862297/1721/2725/63530/23050/53588/10/john/37

Refer to my answer to this question: 请参阅我对这个问题的回答:

php, handle unique URLs php,处理唯一的URL

This will give you this: 这将为您提供:

http://mysite.com/15751890/862297/1721/2725/63530/23050/53588/10/john/37

Instead of trying to figure out every rewrite combination possible, you should learn the MVC routing method. 与其尝试找出所有可能的重写组合,不如学习MVC路由方法。

This way, you route everything to a PHP router, and then direct the request to controllers, etc, as needed. 这样,您可以将所有内容路由到PHP路由器,然后根据需要将请求定向到控制器等。

HTACCESS to rewrite everything: HTACCESS重写所有内容:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

In your PHP script, you can use: $_SERVER['REQUEST_URI'] to get the requested URI. 在您的PHP脚本中,您可以使用: $_SERVER['REQUEST_URI']获取请求的URI。

Example: http://example.com/foo/bar/95 would rewrite to index.php, and $_SERVER['REQUEST_URI'] would then be /foo/bar/95 - and then you route accordingly. 示例: http : //example.com/foo/bar/95将重写为index.php,然后$_SERVER['REQUEST_URI']将为/foo/bar/95然后进行相应的路由。

Typically, your URL structure would be like: 通常,您的URL结构如下所示:

http://example.com/controller/action/param_1/param_2/param_3/etc http://example.com/controller/action/param_1/param_2/param_3/etc

Whereas "action" is just another name for a controllers method. 而“动作”只是控制器方法的别称。 How you code it is up to you. 如何编写代码取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM