Link to home
Start Free TrialLog in
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.
Avatar of Brad Howe
Brad Howe
Flag of Canada image

Try this,

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

ASKER

This is not working.
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
Avatar of 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

Avatar of vkadian

ASKER

Can anyone please help
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
Avatar of vkadian

ASKER

cheers hades666. Your help will be appreciated a lot.
Avatar of vkadian

ASKER

hades666 have you tested it out.
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
Avatar of 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
Thank you, that is different then just a simple rewrite rule.  I am installing WP and will see I can do.
Thanks,
Hades666
Avatar of 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
ASKER CERTIFIED SOLUTION
Avatar of Brad Howe
Brad Howe
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
Avatar of vkadian

ASKER

Brilliant man! I got it working.