简体   繁体   English

重写id .htaccess的规则

[英]Rewrite Rule for id .htaccess

Is there any possibility to rewrite url's with get variables globally, instead of specific files? 是否有可能使用全局get变量重写url,而不是特定文件?

Changing 更改

http://example.com/{something}?id=1

To: 至:

http://example.com/{something}/id/1

Or without the word id: 或者没有单词id:

http://example.com/{something}/1

This is what I got so far: 这是我到目前为止所得到的:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.phtml
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.phtml
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$

With this I could remove the .phtml extension 有了这个,我可以删除.phtml扩展名

I hope there is a specific answer for this! 我希望有一个具体的答案!

I am assuming something to be a php file, 我假设某事是一个php文件,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/id/([\d]+)$ $1.php?id=$2 [L] #with id in between

or 要么

RewriteRule ^([\w-]+)/([\d]+)$ $1.php?id=$2 [L] #without id in between

You have to make sure rules are not conflicting. 你必须确保规则不冲突。

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

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