的.htaccess pretty的URL重写的子文件夹PHP页面? [英] .htaccess Pretty URL rewrite for PHP pages in a subfolder?

查看:133
本文介绍了的.htaccess pretty的URL重写的子文件夹PHP页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的目录设置:

http://www.mysite.com/public/

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

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

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

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

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

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

  http://www.mysite.com/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:

http://www.mysite.com/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\.com
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:

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

...should be rewritten to something like:

http://www.mysite.com/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\.com$ [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页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆