我的.htaccess
文件中存在一些问题。
我想显示此网址的内容:
http://mywebsite.com/admin/payments/invoices/view/index.php?id=123456
当我访问这个时:
http://mywebsite.com/admin/payments/invoices/view/123456/
这是我的实际.htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /admin/payments/invoices/
RewriteRule ^/view/([0-9]+)/(index.php)?$ /view/index.php?id=$1 [L,QSA]
你有什么想法吗?
谢谢!
答案 0 :(得分:1)
如果您有view
目录,那么最简单的方法是将此.htaccess
放在该目录中(即{DOCUMENT_ROOT}/admin/payments/invoices/view/.htaccess
):
Options +FollowSymlinks
RewriteEngine On
RewriteBase /admin/payments/invoices/view
RewriteRule ^(\d+)$ index.php?id=$1 [L,QSA]
RewriteRule
左侧的index.php不是必需的(实际上,我希望它不起作用:在这个阶段,DirectoryIndex
还不应该在URI中注入 - 除非其他RewriteRule
生效?),RewriteBase
的末尾也不是。
我在Apache / 2.2.21上测试了上述内容,但模块规则对于以后的版本是相同的。
答案 1 :(得分:0)
试试这个:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*admin/payments/invoices/view/index\.php\?id=([0-9]+) admin/payments/invoices/view/$1/index.php [L]
</IfModule>
答案 2 :(得分:0)
尝试将其放入文档根目录中的htaccess文件中:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)id=([0-9]+)
RewriteRule ^admin/payments/invoices/view/index\.php$ /admin/payments/invoices/view/%1/index.php [L]
因此,当您在浏览器的网址栏中输入http://mywebsite.com/admin/payments/invoices/view/index.php?id=123456
时,您将获得/admin/payments/invoices/view/123456/index.php
的内容。 Since it's completely unclear what you actually want,如果你想要反过来:
RewriteEngine On
RewriteRule ^admin/payments/invoices/view/([0-9]+)/(index.php)?$ /admin/payments/invoices/view/index.php?id=$1 [L,QSA]