开发者

Mod_rewrite forward everything to index.php 's params

开发者 https://www.devze.com 2023-01-17 03:22 出处:网络
How can I get anything but files to rewrite to index.php\'s params? I\'m using apache,开发者_StackOverflow中文版 mod_rewrite, etc.If you want to rewrite anything that isn\'t a request for a regular fi

How can I get anything but files to rewrite to index.php's params? I'm using apache,开发者_StackOverflow中文版 mod_rewrite, etc.


If you want to rewrite anything that isn't a request for a regular file I'd use this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/index\.php -f
    RewriteRule ^(.*)$  /index.php?page=$1 [QSA]
</IfModule>

This way you don't need to concern yourself about adhering to a certain URL format for your rewrites - you can test and act accordingly in your serving script.


Try this:

RewriteRule /([^/]*)/([^/]*)/([^/]*)[^\.].*  /index.php?var1=$1&var2=$2&var3=$3 [R=301]

This will redirect url like /foo/bar/baz to /index.php?var1=foo&var2=bar&var3=baz

0

精彩评论

暂无评论...
验证码 换一张
取 消