2017-06-03 82 views
0

的网址我想使用URL重写我的.htaccess重定向我不漂亮网址:Transfert与参数成为一个漂亮的URL与htaccess的

http://example.com/_new/url.php?module=planning&action=see&id=2

这一个:

http://example.com/_new/url/planning/see/2

所以我用:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)$ url.php?module=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+)$ url.php?module=$1&action=$2 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ url.php?module=$1&action=$2&id=$3 [L] 

但它不起作用。

请帮忙吗?

谢谢。

回答

0

对于这个特定的URL重写,你可能需要更换您的[重写规则]对这样的事情:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^_new/url/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ _new/url.php?module=$1&action=$2&id=$3 [NC,L]

从中你可以访问:http://example.com/_new/url.php?module=planning&action=see&id=2

http://example.com/_new/url/ {module_name} = http://example.com/_new/url.php?module= {module_name}

这同样适用于$ 2 ,也是3美元。

[NC] =不区分大小写:这个标志告诉apache会有[任何情况下]

[L] =如果这个规则已经被处理,首先,没有额外的规则将在当前被添加URL重写过程

您可以了解更多关于此:https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

希望这有助于。

+0

你好,我有这个错误:'请求的URL /_new/url/planning/see/2.php在这个服务器上找不到.' –

+0

你现在解决了你的问题吗? – eeya