Avatar of vkadian
vkadian
 asked on

Rewrite wordpress /search/ query url to something else such as /ideas/ etc.

Rewrite wordpress /search/ query url to  something else such as /ideas/ etc.
PHPApache Web ServerWordPress

Avatar of undefined
Last Comment
vkadian

8/22/2022 - Mon
Brad Howe

Try this,

RewriteCond %{REQUEST_URI} ^/search/
RewriteRule ^/search/$  /ideas/ [R]
vkadian

ASKER
This is not working.
Brad Howe

Add this, Sorry. You need to add the RewriteEngine. I did just test this and it does work, IF you webserver is configured to allow rewrites.

How to setup:
Create an .htaccess file in the top directory above /search/ and /ideas/.
This assumes a directory structure like such.

/ root
   .htaccess   <-- Place file here.
         /ideas

This file will contain.
---
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/search/
RewriteRule ^search/$ /ideas/ [R]
---

Cheers,
Hades666
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
vkadian

ASKER
Hi, Hades. I am already using rewrite rules for wordpress and my .htaccess files contains the followoing rules already.

addhandler x-httpd-php5-cgi .php5
addhandler x-httpd-php5-cgi .php


# Begin Cache Control
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/x-icon A86400
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A86400
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000
ExpiresByType application/pdf A2592000
ExpiresByType text/html A600
</IfModule>
#End Cache Control
# BEGIN WPSuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
</IfModule>
# END WPSuperCache
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Open in new window

vkadian

ASKER
Can anyone please help
Brad Howe

Hi vkadian,

I will apply your .htaccess file to my Apache vm and see what we can do. The above rules do work but it may be that you have conflicting rules with your current base.

I will try and let you know sometime tomorrow.

Cheers,
Hades666
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
vkadian

ASKER
cheers hades666. Your help will be appreciated a lot.
vkadian

ASKER
hades666 have you tested it out.
Brad Howe

Yes, I added the same ruleset I previous posted and any address in the form of www.domain.com/search gets redirected to www.domain.com/ideas.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /          <------------------------ This should be the top directory .htaccess where /search and /ideas resides
RewriteCond %{REQUEST_URI} ^/search/
RewriteRule ^search/$ /ideas/ [R]
</IfModule>

ex:
<wwwroot />
        <dir1>
              <wordpress>   <--- In this case, the ruleset above would go in .htaccess in this folder.
                       <search>
                       <ideas>    
 
Let me know,
Hades666
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
vkadian

ASKER
hades666, I do not have a directory for 'search' or 'ideas' because the results are produced dynamically in Wordpress (within the index file using get method - http://speedywap.com/?s=searchterm" but the urls are rewritten to show them as if they are directories.
I think you did not know this so I though of informing you about this because I do not have those directories. If this is somehow possible by creating those categories can you please suggest me how to do that. Thanks.

Also, if you know a lot about wordpress core then there is a file called wp-rewrite.php, in the wp-includes folder, which contains the rewrite rules.

Thanks,
VKadian
Brad Howe

Thank you, that is different then just a simple rewrite rule.  I am installing WP and will see I can do.
Thanks,
Hades666
vkadian

ASKER
Hades, I will appreciate your solution so much. Can you please take a look at this question as well - https://www.experts-exchange.com/questions/25195224/Rewrite-Urls.html
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Brad Howe

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
vkadian

ASKER
tried that but that doesn't make a difference! I don't know why? I was expecting it to rewrite the urls as well but it still only works with the old ones.
Cheers,
Vkadian
vkadian

ASKER
Brilliant man! I got it working.