Replace white space%20 white - in search url - .htaccess

I tried a lot of code without results.
I'm using wordpress and the url of search results is:
http://mysite.com/search/the%20search%20query%20
I need to change it in
http://mysite.com/search/the-search-query/
Is there a way with htaccess?
This is actually my htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Options +FollowSymlinks -MultiViews
RewriteRule ^(.+)(\s|%20)(.+)$ /$1-$3 [R=301,QSA,L,NE]
# END WordPress
The last rewrite rule is what i trie without success

Your rule looks fine, however you have it after your routing rules. That means no matter what, that rule will never be reached because everything, including any request with a space in it, gets routed to index.php. You need to put any redirect rules before your routing rules:
Options +FollowSymlinks -MultiViews
RewriteRule ^(.+)(\s|%20)(.+)$ /$1-$3 [R=301,QSA,L,NE]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Related

Redirecting 404s using 301 redirects with .htaccess

The .htaccess file I'm editing contains the following code for redirecting http://www.example.com to http://example.com:
AddHandler fcgid54-script .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Without writing a new .htaccess file from scratch, I'm looking to redirect a few other pages that are returning 404s. I tried the following but it didn't work:
AddHandler fcgid54-script .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
301 Redirect /blank/blah/page/ http://example.org/blank/blah/
# END WordPress
I've also tried a bunch of other other iterations, but nothing is working so far.
Don't mix mod_rewrite rules with mod_alias ones and keep 301 before internal WP rule:
AddHandler fcgid54-script .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^blank/blah/page/?$ http://example.org/blank/blah/ [L,NC,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
try this it will work :
ErrorDocument 404 http://www.example.com/abc.html
By adding this line in htaccess file, pages that are returning 404s are forwarded to the specified url. such as http://www.example.com/abc.html

Rewrite in htaccess not working

I have a page locally that is /shop but I want it to redirect to /shop/designs
I tried to do it with .htaccess but nothing seems to be working.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/shop/.*$ /shop/designs/ [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any ideas where I am going wrong?
You were almost there, but in htaccess, you cannot use / at the beginning of the path regex.
Change your rule like so:
RewriteEngine On
RewriteRule ^shop$ shop/designs [R=301,L]

htaccess mod_rewrite - reroute all urls to index except /admin

I'm setting up a small set of rewrite rules in an htaccess file, where I want every url to go to a index.php file except for /admin which I want to redirect to admin.php. Not very familiar with mod_rewrite or regexp unfortunately.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin.php [L]
RewriteRule . /index.php [L]
</IfModule>
This gives me an internal server error (not saying 500). Removing or uncommenting the admin rewrite makes it work.
The conditions need to be applied to the index.php rewrite rule, otherwise it causes a redirect loop. A RewriteCond only gets applied to the immediately following RewriteRule so the rule that routes everything to index has no conditions. Try just rearranging the lines:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^admin$ admin.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

.htaccess redirect - how to go from /about to /our-story

I'm trying to make it so that anything at /about goes to /our-story.
I think my .htaccess redirect rule is correct for this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
The line is here:
RewriteRule ^about.*$ http://domain.com/our-story/ [R=301,L]
</IfModule>
However it doesn't seem to work. My suspicion is that this is due to Wordpress being active. I tried to put it inside the Wordpress block though, and still it doesn't work.
What do I have to do to redirect from /about to /our-story?
The rule is correct, but they need to go before the wordpress rules because you are redirecting while the wordpress rules routes everything into /index.php. Any request URI that starts with /about will end up getting routed to wordpress and thus never get redirected. Just switch the order:
RewriteRule ^about.*$ http://domain.com/our-story/ [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I need a Wordpress folder to NOT be case sensitive without writing 200 redirects

I have a blog set up at blog.ftj.com/ACSM, it is hosted with Bluehost and their folder structures seem to be case sensitive. Is there something in the .htaccess file that I can adjust so that all possible combinations get redirected to the specific uppercase URL.
Another issue is that it seems that I need to redirect
blog.ftj.com/acsm/
with and without the forward slash.
Here is my current .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ACSM/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ACSM/index.php [L]
</IfModule>
# END WordPress
Please submit the full change if you would.
You need to place the following .htaccess in the root dir to rewrite all requests to /ACSM into /acsm
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/acsm$ [NC]
RewriteRule ^(.*)$ /ACSM [L]
RewriteCond %{REQUEST_URI} ^/acsm/(.*)$ [NC]
RewriteRule ^acsm/(.*)$ /ACSM/$1 [L]
</IfModule>
Sorry for delays, have not got an Apache at hands....

Resources