我的脚本的 PHP 友好 URL
我有一个网站,我已将其转换为使用 cms 变得简单。它工作得很好,而且我的友好网址也工作得很好。我的问题是我自己编写的一个小脚本以及如何最好地集成它。该脚本是一个画廊脚本,它读取一个目录并以 html 格式输出一个格式化的画廊。我计划将其设为 cms 中的用户定义标签,变得简单,但遇到了一个小障碍。
图库脚本需要能够从 url groupId 和 showpage 读取两个值。
如果我使用友好的网址,那么CMS并使用标签,当CMS尝试在“www.mysite.com/gallery/mygroup/2”找到实际页面,然后抛出404时,我遇到了障碍。
基本上我需要
http://www.mysite.com/gallery/photogroup/2
重写到
http://www.mysite.com/gallery.php?groupId=photogroup&showpage=2
更新 按照 Yuri 的建议,我将他的规则添加到了 htaccess 中。但我遇到了另一个障碍。 例如如果我们去 http://www.mysite.com/gallery/photogroup/2
那么尤里的规则就应该生效了。但巧合的是,该路径也是我网站上的正确物理目录。有没有办法让重写规则生效,而不是让我进入白屏浏览目录中的文件或进入禁止屏幕(如果我关闭了索引)。
下面是我的htaccess
php_flag magic_quotes_gpc Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1
RewriteRule ^gallery/(\w+)/(\d+)$ gallery.php?groupId=$1&showpage=$2 [QSA,L]
I have a site which I have converted to use cms made simple. It works perfectly and I have the friendly urls working fine too. My issue is with a little script I wrote myself and how best to integrate it. The script is a gallery script, it reads a directory and outputs a formatted gallery in html. I was planning on making it a user defined tag in cms made simple but I hit a small snag.
The gallery script needs to be able to read in two values from the url groupId and showpage.
If I am using freindly urls then the cms and use the tag I hit a snag as the cms tries to find an actual page at "www.mysite.com/gallery/mygroup/2" and then throws a 404.
basically I need
http://www.mysite.com/gallery/photogroup/2
rewritten to
http://www.mysite.com/gallery.php?groupId=photogroup&showpage=2
UPDATE
Follwoing Yuri's advice I added his rule to the htaccess. But I have hit another snag.
So for instance if we go tohttp://www.mysite.com/gallery/photogroup/2
then Yuri's rule should take effect. But that path is also a correct physical directory on my site coincidentally. Is there a way to have the rewrite rule take effect instead of bringing me to a white screen browsing the files in the directory or to the forbidden screen if I have indexes turned off which I do.
Below is my htaccess
php_flag magic_quotes_gpc Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1
RewriteRule ^gallery/(\w+)/(\d+)$ gallery.php?groupId=$1&showpage=$2 [QSA,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么,您是否尝试在
.htaccess
中编写类似的内容?So, did you try to write in
.htaccess
something like this?对我来说听起来像是一个“模块”。也许这个让你的模块使用干净的URL
sounds like a "module" to me. Maybe this Make your module use clean URLs