21

I want to change the URL from:

http://example.com/Portfolios/iPhone/app

To:

http://example.com/iPhone/app

And same for all URLs like:

example.com/Portfolios/iPad/app

To:

example.com/iPad/app

And from:

example.com/Portfolios/xyz/app

To:

example.com/xyz/app

I have tried a lot but nothing is working for me.


<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^Portfolios(/.*|)$ $1 [L,NC]  
</IfModule>
4

2 回答 2

32

启用mod_rewrite.htaccess通过httpd.conf然后将此代码放在您.htaccessDOCUMENT_ROOT目录中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^Portfolios/(.*)$ /$1 [L,NC,R]

说明:Portfolios上面的/Portfolios/xyz/app规则是匹配xyz/app$1. /$1它对ie进行外部重定向/xyz/app

这些是使用的标志:

L  - Last
NC - Ignore (No) Case comparison
R  - External redirection (with 302) -- can be changed to R=301
于 2013-09-24T04:41:45.343 回答
0

您还可以将根目录设置为 /var/www/Portfolios 而不是 /etc/apache2/sites-enabled 通过将 DocumentRoot 行编写为

DocumentRoot /var/www/Portfolios

而不是 DocumentRoot /var/www/ 并且这一行 < Directory /var/www/ > 更改为

< 目录 /var/www/Portfolios/ >

于 2014-03-25T07:23:29.810 回答