的.htaccess pretty的网址网址、htaccess、pretty

2023-09-02 00:38:35 作者:湮落缪苏

我想提出我的网址pretty的与htaccess的。

我只有一个变量 - ID。因此,网页都喜欢的index.php?ID = 1,的index.php?ID = 2等。 我想他们会是:/ 1 /,/ 2 / - 像文件夹,而不是id变量...

我如何可以完成,使用的htaccess重写URL?

我试图做这样的:

 < IfModule mod_rewrite.c>
 的RewriteCond%{} SCRIPT_FILENAME!-d
 的RewriteCond%{} SCRIPT_FILENAME!-f
 重写规则^([^ /] +)的index.php?编号= $ 1 [L]
< / IfModule>
 

解决方案

这对我的作品:

  RewriteEngine叙述上
的RewriteCond%{} SCRIPT_FILENAME!-d
的RewriteCond%{} SCRIPT_FILENAME!-f
重写规则^([^ /] +)的index.php?编号= $ 1 [L]
 
DA HtAccess 网站htaccess配置文件创建工具

如果index.php文件是这样的:

 < PHP
import_request_variables('G','req_');
后续代码var_dump($ REQ_ID);
 

和你犯了一个请求的http://域名/ 1

那么index.php文件具有可变REQ_ID = 1(因为import_request_variables调用)

I would like to make my urls pretty with htaccess.

I have only one variable - id. So the pages are like index.php?id=1, index.php?id=2 etc. What I would like them to be is: /1/, /2/ - like folders, instead of id variable...

How can I accomplish that using htaccess rewrite urls?

I was trying to do it like that:

<IfModule mod_rewrite.c>
 RewriteCond %{SCRIPT_FILENAME} !-d
 RewriteCond %{SCRIPT_FILENAME} !-f
 RewriteRule ^([^/]+) index.php?id=$1[L]
</IfModule>

解决方案

This works for me:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^/]+) index.php?id=$1 [L]

if the index.php file is something like this:

<?php
import_request_variables('g', 'req_');
var_dump($req_id);

and you make a request to http://domain/1

then index.php has the variable req_id=1 (because of the import_request_variables call)