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

由网友(转身 泪痕残留依旧。)分享简介:我有以下的目录设置:http://www.mysite.com/public/ 我用下面的重写删除公共文件夹,从可见光网址:#rewrite的URL显示子目录作为所有环节的主目录的RewriteCond%{HTTP_HOST} ^(WWW \)?mysite的\ .COM的RewriteCond%{REQUEST...

我有以下的目录设置:

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
 
WIN7 系统 PHP环境搭建 及iis7的URL重写

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

  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.

阅读全文

相关推荐

最新文章