[英]how can i rewrite my url for only certain pages
如何使用.htaccess仅重写某些页面的URL?
例如,我希望它能在index.php上工作,但不能在网站上的其余页面上工作,也不能在除index.php之外的所有页面上工作。
我遇到了子域和php脚本的问题,在这些问题中,我正在使用的URL重定向会弄乱东西。 以下是我要使用的脚本类型的示例。
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php/?node=$1&id=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php/?node=$1 [L,QSA]
谁能指出我正确的方向?
您可以将URL作为REQUEST_URI服务器变量传递:
RewriteCond %{REQUEST_URI} ^(your_url)$
RewriteRule %1 do_some_stuff
举个例子:
RewriteCond %{REQUEST_URI} ^index.php$
RewriteRule %1 - [F]
或者只是将其传递给RewriteRule
:
RewriteRule ^index.php$ do_some_stuff
您应该查看.htaccess的RewriteCond
(条件) 。有关许多信息和示例,请参见http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/ 。
您也可以只为index.php编写一条规则,然后将其标记为最后一条规则[l]
RewriteRule ^/index.php(.*) /index.php$1 [L]
RedirectRule ^/(.*)$ /index.php?path=$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.