我想重写网址,以便有人去:
url.com/directory1/directory2
他在浏览器地址栏中看到了网址,但实际上以下网址显示的是文字
url.com/index.php/directory1/directory2
基本上,网址url.com/directory1/directory2
转到url.com/index.php/directory1/directory2
如何使用.htaccess和/或mod_rewrite执行此操作?那个重写规则是什么?
答案 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