Question

I'm trying to remove index.php from WordPress URLS.

I have this code in my httpd.ini file

[ISAPI_Rewrite]

RewriteCond Host: domain\.com
RewriteRule (.*) http\://www.domain.com$1 [I,RP]

RewriteRule /(?!index\.php)([^/.]+)/ /index.php/$1 [I]

RewriteRule /(?!index\.php)([^/.]+) /index.php/$1 [I,L]

This works but only for the category, for example domain.com/gear works, but domain.com/gear/post doesn't.

I found this post, but I couldn't really follow it http://www.helicontech.com/forum/14820-Wordpress_Permalinks_for_ISAPI_Rewrite_2.html

Any suggestions?

Était-ce utile?

La solution

Try the following solution:

[ISAPI_Rewrite]

RewriteCond Host: domain\.com
RewriteRule (.*) http\://www.domain.com$1 [I,RP]

RewriteRule /(?!index\.php)([^.]+?)/? /index.php/$1 [I,L]

Autres conseils

I know this is an older post, but in case you still need solution or another suggestion, here is what worked for me, and for what scenario.

When you are trying to run WordPress in shared hosting environment, running Windows 2003 with IIS 6 server, you might run into and issue with custom permalinks where custom permalinks might not work, such as /%postname%/ would return 404 error.

If your ISP has ISAPI_Rewrite 2 installed and using ISAPI_Rewrite to redirect traffic to different sites, this might work for you. I've shortened httpd.ini to show how this works for two instances of WordPress.

This httpd.ini sits in the root of all your sites and has rules for all your sites.

[ISAPI_Rewrite]

### subdomain redirect v2 ###
RewriteCond Host: (?:.+\.)?your-domain-name1\.com
RewriteCond URL ^/site-path1/(.*)
RewriteCond METHOD GET
RewriteRule ^/site-path1/(.*) /$1 [I,R]
RewriteCond Host: (?:.+\.)?your-domain-name1\.com
RewriteCond METHOD POST
RewriteRule ^/site-path1/(.*) /$1 [I]
RewriteCond Host: (?:.+\.)?your-domain-name1\.com
### RewriteRule (.*) /site-path1/$1 [I,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/wp-admin/?$ /newhat/wp-admin/index.php [I,L]
RewriteRule ([^.]*) /site-path1/index.php/$1 [I,L]
RewriteRule (.*) /site-path1/$1 [I,L]

### subdomain redirect v2 ###
RewriteCond Host: (?:.+\.)?your-domain-name2\.com
RewriteCond URL ^/site-path2/(.*)
RewriteCond METHOD GET
RewriteRule ^/site-path2/(.*) /$1 [I,R]
RewriteCond Host: (?:.+\.)?your-domain-name2\.com
RewriteCond METHOD POST
RewriteRule ^/site-path2/(.*) /$1 [I]
RewriteCond Host: (?:.+\.)?your-domain-name2\.com
### RewriteRule (.*) /site-path2/$1 [I,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/wp-admin/?$ /newhat/wp-admin/index.php [I,L]
RewriteRule ([^.]*) /site-path2/index.php/$1 [I,L]
RewriteRule (.*) /site-path2/$1 [I,L]

The line ### RewriteRule (.*) /site-path2/$1 [I,L] in uncommented version was the last line of the original ISP configuration before modifications. I inserted 4 new lines just before it:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/wp-admin/?$ /newhat/wp-admin/index.php [I,L]
RewriteRule ([^.]*) /site-path2/index.php/$1 [I,L]

This SO link explains Rewrite rules.

My understanding of this line RewriteRule ([^.]*) /site-path2/index.php/$1 [I,L] is, for any URL that does not contain period, rewrite it to append index.php. This is why it needs to be before (.*) line which picks up everything.

Admin toolbar, if it is shown has a link to the /wp-admin/ without specifying index.php which rule RewriteRule ^/wp-admin/?$ /newhat/wp-admin/index.php [I,L]

Another article/site that helped with this was online Apache mod_rewrite tester.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top