lizardhr
lizardhr

Reputation: 310

Wordpress .htaccess Rewrite doesn't take effect

I have these rules in wordpress .htaccess:

<IfModule mod_speling.c>
CheckSpelling on
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/

RewriteCond %{THE_REQUEST} (\.htm|\.html)
RewriteRule ^(.*)(\.htm|\.html)$ http://test.com/wordpress/$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^(/wordpress/|/wordpress/images/)
RewriteRule ^(.*\.jpg)$ /wordpress/$1 [R=301,L]

I need to trigger this other rule that will apply a %20 replace only for file names, but it doesn't take effect:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*)(\ |\%20)(.*)  /wordpress/$1-$2 [R=301,L]

Example of URL I need to test is:

http://test.com/some Folder/some Other subfolder/Some File Name.jpg

Needed Result:

http://test.com/wordpress/some Folder/some Other subfolder/some-file-name.jpg

Where I'm doing wrong? How can I accomplish with that?

Upvotes: 0

Views: 156

Answers (1)

anubhava
anubhava

Reputation: 785246

Try this rule in your DocumentRoot/.htaccess for replacing white-spaces with hyphens:

RewriteRule ^(?:wordpress/)?(.*/)?([^\s\x20/]*)[\s\x20]+([^/]*)$ /wordpress/$1$2-$3 [R=302,L,NE]

Upvotes: 1

Related Questions