2015-05-19 128 views
0

我的网站上的URL结构如下:http://www.mydomain.tld/index.php/pages/sitename。现在我想删除index.php/pages,让URL结构如http://www.mydomain.tld/sitename。此外,我想重新命名一些sitename的个人。使用mod_rewrite删除index.php和文件夹名称

我已经删除了index.php,那没问题。所以,目前我的.htacces-文件看起来像

DirectoryIndex index.php 
RewriteEngine on 

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico|pam) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ ./index.php?$1 [QSA,L] 

RewriteCond %{HTTP_HOST} ^mydomain.tld\.de$ [NC] 
RewriteRule ^(.*)$ http://www.mydomain.tld/$1 [R=301,L] 

但是,如果我追加/pages到第一的RewriteCond或重写规则,这是行不通的。 你有什么想法吗?

回答

0

有你的.htaccess这样的:

DirectoryIndex index.php 

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^mydomain.tld\.de$ [NC] 
RewriteRule ^(.*)$ http://www.mydomain.tld/$1 [R=301,L,NE] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^((?!index\.php/pages/).*)$ index.php/pages/$1 [NC,L] 
+0

感谢您的帮助,但我认为这是行不通的。我仍然使用www.mydomain.tld/sitename获得404。我不能使用NE和第一个RewriteRule。如果我使用它,我无法通过http://mydomain.tld进入我的网站。 – pexmar

+0

你可以离开'NE'。也尝试我更新的规则。 – anubhava

+0

不,不幸的是,这也行不通 – pexmar

相关问题