[英]how can i rewrite my url for only certain pages
How can I use .htaccess to rewrite URL for certain pages only? 如何使用.htaccess仅重写某些页面的URL?
For example, I want it to work on index.php but not the rest of the pages on the site or on all pages but index.php. 例如,我希望它能在index.php上工作,但不能在网站上的其余页面上工作,也不能在除index.php之外的所有页面上工作。
I run in to issues with sub domains and php scripts where the URL redirecting that I am using will mess up stuff. 我遇到了子域和php脚本的问题,在这些问题中,我正在使用的URL重定向会弄乱东西。 Below is an example of the kind of script I want to use.
以下是我要使用的脚本类型的示例。
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]
Can anyone point me in the right direction? 谁能指出我正确的方向?
You can pass URL as REQUEST_URI server variable: 您可以将URL作为REQUEST_URI服务器变量传递:
RewriteCond %{REQUEST_URI} ^(your_url)$
RewriteRule %1 do_some_stuff
As an example: 举个例子:
RewriteCond %{REQUEST_URI} ^index.php$
RewriteRule %1 - [F]
Or just pass it in RewriteRule
: 或者只是将其传递给
RewriteRule
:
RewriteRule ^index.php$ do_some_stuff
You should check out RewriteCond
(conditions) for .htaccess Check http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/ for a lot of information and examples. 您应该查看.htaccess的
RewriteCond
(条件) 。有关许多信息和示例,请参见http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/ 。
You could also write a rule just for index.php and then flag it as the last rule [l]
您也可以只为index.php编写一条规则,然后将其标记为最后一条规则
[l]
RewriteRule ^/index.php(.*) /index.php$1 [L]
RedirectRule ^/(.*)$ /index.php?path=$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.