的.htaccess pretty的URL重写的子文件夹PHP页面?

编程入门 行业动态 更新时间:2024-10-22 10:46:51
本文介绍了的.htaccess pretty的URL重写的子文件夹PHP页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下的目录设置:

www.mysite/public/

我用下面的重写删除公共文件夹,从可见光网址:

#rewrite的URL显示子目录作为所有环节的主目录 的RewriteCond%{HTTP_HOST} ^(WWW \)?mysite的\ .COM 的RewriteCond%{REQUEST_URI}!^ /公 重写规则^(。*)$ /公/ $ 1 [L]

这个伟大的工程,并正确地重定向一切。不过,我也想重写一些生活在公共子文件夹以及动态页面,但我无法得到任何我发现在协同工作与上述规则的重写的。

例如,在发生上述子目录重写规则,将一个网址,如:

www.mysite/item.php?id=1&name=item_name

...应该重写是这样的:

www.mysite/items/item_name

思考?

解决方案

选项+了FollowSymLinks -MultiViews RewriteEngine叙述上 的RewriteBase / #rewrite的URL显示子目录作为所有环节的主目录 的RewriteCond%{HTTP_HOST} ^(WWW \)?mysite的\ .COM $ [NC] 重写规则^(?公共/ |打印/)(.*)$ /公/ $ 1 [L,NC] 的RewriteCond%{} THE_REQUEST /*item\.php\?id=([^&]*)&name=([^&]*)\s [NC] 重写规则^ /打印/ 1%/ 2%? [R,L,NC] 重写规则^打印/([^ /] *)/([^ /] *)/ $公共/ item.php的id = $ 1和;?名= $ 2 [L,NC QSA]

PS:请确保您的静态包括如CSS,JS,图片等有绝对路径,而不是一个相对

I've got the following directory setup:

www.mysite/public/

I'm using the following rewrite to remove the 'public' folder from visible URLs:

#rewrite the URL to display the subdirectory as the main directory for all links RewriteCond %{HTTP_HOST} ^(www\.)?mysite\ RewriteCond %{REQUEST_URI} !^/public Rewriterule ^(.*)$ /public/$1 [L]

This works great, and redirects everything correctly. However, I also want to rewrite some of the dynamic pages that live in the 'public' subfolder as well, but am having trouble getting any of the rewrites I've found to work in conjunction with the above rule.

For example, with the above subdirectory rewrite rule in place, going to a URL like:

www.mysite/item.php?id=1&name=item_name

...should be rewritten to something like:

www.mysite/items/item_name

Thoughts?

解决方案

Options +FollowSymlinks -MultiViews RewriteEngine on RewriteBase / #rewrite the URL to display the subdirectory as the main directory for all links RewriteCond %{HTTP_HOST} ^(www\.)?mysite\$ [NC] Rewriterule ^(?!public/|prints/)(.*)$ /public/$1 [L,NC] RewriteCond %{THE_REQUEST} /*item\.php\?id=([^&]*)&name=([^&]*)\s [NC] Rewriterule ^ /prints/%1/%2? [R,L,NC] Rewriterule ^prints/([^/]*)/([^/]*)/?$ public/item.php?id=$1&name=$2 [L,NC,QSA]

PS: Make sure your static includes like css, js, images etc have absolute path rather than a relative one.

更多推荐

的.htaccess pretty的URL重写的子文件夹PHP页面?

本文发布于:2023-11-01 20:16:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550308.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   文件夹   页面   pretty   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!