mod_rewrite网址

时间:2011-09-11 12:00:09

标签: .htaccess mod-rewrite

我想重写网址,以便有人去:

url.com/directory1/directory2 

他在浏览器地址栏中看到了网址,但实际上以下网址显示的是文字

url.com/index.php/directory1/directory2 

基本上,网址url.com/directory1/directory2转到url.com/index.php/directory1/directory2

如何使用.htaccess和/或mod_rewrite执行此操作?那个重写规则是什么?

1 个答案:

答案 0 :(得分:4)

在你的.htaccess文件中使用:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/(.*)(\/?)$ /index.php/$1/$2 [NC,QSA,L]
httpd.conf

中的

OR

<VirtualHost *:80>
    DocumentRoot "/var/www/"
    ServerName www.url.com   
    ServerAlias www.url.com
    <Directory /path/to/www/> 
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteRule ^(.*)/(.*)(\/?)$ /index.php/$1/$2 [NC,QSA,L]
    </Directory>
</VirtualHost>

如果您使用PHP:

$_SERVER['REQUEST_URI']/asd/asd