现代重写和PHP重写、现代、PHP

2023-09-02 00:46:43 作者:呆萌小甜心

我试图重定向使用mod_rewrite与一些变量的网页页面(使用它们与PHP的 $ _ GET )。

要举个例子有几行:

当用户进入 / C /英镑重定向到 item_show.php 1 ID = $&放大器; F = 1 (其中 F 为页码)。 当用户进入 / C /英镑/ 2 重定向到第二页有 show.php 1 ID = $&放大器; F = $ 2

我觉得有这些没有任何错误或误用在我的​​文件,但,这里就是我想要的:

我要用户输入 / 字符串 的直接去 item_show.php ID 1 = $&放大器; F = 1 $ 1 是我们的字符串的课程..

但是,当我从重写规则删除 / C / 部分它开始让所有的错误更改我的文件其他目录,无法读取任何文件( my.css ),即使我已经定义了一个的RewriteCond%{} REQUEST_FILENAME!-f ...

$

你有什么建议吗? 或者,我怎么能做出这种系统可以使用任何方法?

 有FollowSymLinks
RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d

#用户
重写规则^ U /([^ /] +)/ $ profile.php?用户名= $ 1 [L,NC]

#marked
重写规则^标记/([^ /] +)/ $ item_marked.php?ID = $ 1 [L,NC]

#内容
重写规则^ C /([^ /] +)/ $ item_show.php ID = $ 1安培;?F = 1 [L,NC]
重写规则^ C /([^ /] +)/([^ /] +)/ $ item_show.php编号= $ 1和;?F = $ 2 [L,NC]
 

解决方案

我是错的,如果的RewriteCond只传递给第一个重写规则??

试试这个来代替:

 有FollowSymLinks
RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d

#用户
重写规则^ U /([^ /] +)/ $ profile.php?用户名= $ 1 [L,NC]

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
#marked
重写规则^标记/([^ /] +)/ $ item_marked.php?ID = $ 1 [L,NC]

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
#内容
重写规则^ C /([^ /] +)/ $ item_show.php ID = $ 1安培;?F = 1 [L,NC]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^([^ /] +)/([^ /] +)/ $ item_show.php编号= $ 1和;?F = $ 2 [L,NC]
 
GitHub 上最火的 PHP 框架

干杯,

I am trying to redirect pages using mod_rewrite to the pages with some variables (for using them with PHP's $_GET).

To give an example with few lines:

When the user enters /c/stg it redirects to item_show.php?id=$1&f=1 (where f is page number). When the user enters /c/stg/2 it redirects to the second page with show.php?id=$1&f=$2.

I think there are no errors or misuses of these in my file but, here's what I want:

I want user to enter /string directly to go item_show.php?id=$1&f=1 with $1 is our string of course...

But when I change my file by removing the /c/ part from RewriteRule it starts giving errors in all other directories and doesn't read any files (my.css) even though I have already defined a RewriteCond %{REQUEST_FILENAME} !-f...

Do you have any suggestions? Or how can I made this system possible with any method?

Options FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#user
RewriteRule ^u/([^/]+)/?$ profile.php?username=$1 [L,NC]

#marked
RewriteRule ^marked/([^/]+)/?$ item_marked.php?id=$1 [L,NC]

#content
RewriteRule ^c/([^/]+)/?$ item_show.php?id=$1&f=1 [L,NC]
RewriteRule ^c/([^/]+)/([^/]+)/?$ item_show.php?id=$1&f=$2 [L,NC]

解决方案

Am I wrong if RewriteCond only are passed on to the first RewriteRule??

Try this instead:

Options FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#user
RewriteRule ^u/([^/]+)/?$ profile.php?username=$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#marked
RewriteRule ^marked/([^/]+)/?$ item_marked.php?id=$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#content
RewriteRule ^c/([^/]+)/?$ item_show.php?id=$1&f=1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ item_show.php?id=$1&f=$2 [L,NC]

Cheers,