[英].htaccess mod_rewrite URL query
I was hoping someone could help me out.我希望有人能帮助我。 I'm building a CRM application and need help modifying the .htaccess file to clean up the URLs.我正在构建 CRM 应用程序,需要帮助修改 .htaccess 文件以清理 URL。 I've read every post regarding .htaccess and mod_rewrite and I've even tried using http://www.generateit.net/mod-rewrite/ to obtain the results with no success.我已经阅读了所有关于 .htaccess 和 mod_rewrite 的帖子,我什至尝试使用http://www.generateit.net/mod-rewrite/来获得结果但没有成功。 Here is what I am attempting to do.这是我正在尝试做的。
To summarize here's what I am looking to do:总结一下我想要做的事情:
(40, 27, and 6 are just arbitrary numbers as examples) (40、27 和 6 只是作为示例的任意数字)
Just for reference, when I used the generateit.net/mod-rewrite site using www.domain.com/crm/company.php?companyID=40 as an example, here is what it told me to put in my .htaccess file:仅供参考,当我以 www.domain.com/crm/company.php?companyID=40 为例使用 generateit.net/mod-rewrite 网站时,它告诉我要放入 .htaccess 文件的内容如下:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^crm/company/([^/]*)$ /crm/company.php?companyID=$1 [L]
Needless to say that didn't work.不用说那没有用。
OK here is an updated based on the help received from Gohn67 below好的,这是根据下面从 Gohn67 收到的帮助进行的更新
It is working with the exception of a small bug I can't seem to figure out.除了一个我似乎无法弄清楚的小错误外,它正在工作。 I have created the .htaccess file in the "crm" directory.我在“crm”目录中创建了 .htaccess 文件。 Here is the code:这是代码:
RewriteEngine On
RewriteRule ^test/([\d]+)$ /crm/company.php?companyID=$1 [L]
This rewrites www.domain.com/test/40 to www.domain.com/crm/company.php?companyID=40 so it's very close to what I need.这将 www.domain.com/test/40 重写为 www.domain.com/crm/company.php?companyID=40 所以它非常接近我需要的。
The bug is that I cannot replace "test" with the word "company" in my RewriteRule.错误是我无法在我的 RewriteRule 中用“公司”一词替换“测试”。 I do not know why.我不知道为什么。 I can put anything but the word "company" in there;除了“公司”这个词,我可以放任何东西; even the names of other PHP files in the "crm" directory such as "contact" or "add-contact".甚至“crm”目录中其他 PHP 文件的名称,例如“contact”或“add-contact”。 As a further test I actually renamed company.php to test.php and changed the RewriteRule to:作为进一步的测试,我实际上将 company.php 重命名为 test.php 并将 RewriteRule 更改为:
RewriteRule ^company/([\d]+)$ /crm/test.php?companyID=$1 [L]
which worked.哪个有效。
Yeah, the generated rewrite looks kind of strange there.是的,生成的重写看起来有点奇怪。 I'm not sure what it is trying to match here ([^/]*)
.我不确定它在这里试图匹配什么([^/]*)
。
Here is an example that may work for you.这是一个可能对您有用的示例。 I tested these on my system.我在我的系统上测试了这些。
RewriteEngine On
RewriteRule ^crm/dash/?$ /crm/dash.php [L]
RewriteRule ^crm/company/([\d]+)/?$ /crm/company.php?companyID=$1 [L]
RewriteRule ^crm/contact/([\d]+)/?$ /crm/contact.php?contactID=$1 [L]
This is only a few of your routes as an example.这只是您的一些路线作为示例。 I admit that they could be more robust though, because doing this way will lead to a lot of rewrite rules, some of which you could elminate with better regex patterns.我承认它们可能更健壮,因为这样做会导致大量重写规则,其中一些您可以使用更好的正则表达式模式来消除。 But hopefully this gets you started.但希望这能让你开始。
Here are some updated rewrite rules taking into consideration a subdirectory.以下是一些考虑到子目录的更新重写规则。 It also fixes aa mistake from above:它还修复了上面的一个错误:
RewriteEngine On
RewriteBase /crm
RewriteRule ^dash/?$ dash.php [L]
RewriteRule ^company/([\d]+)/?$ company.php?companyID=$1 [L]
RewriteRule ^contact/([\d]+)/?$ contact.php?contactID=$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.