This is my current .htaccess file content:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I want to change:
http://example.com/search/?location=&radius_key=sydney/&keyword=&geolocation=
to:
http://example.com/massage/sydney/
I have modified script as below but it's not changing my URL. Could you please guide me. Any kind of response to fix this problem is highly appreciated. Thanks
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/massage/(.*)$ /search/? location=&radius_key=$1&keyword=&geolocation=
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If you want the URL displayed in the browser address bar to change, you have to activate the "R" flag in modrewrite, which activate the Redirection.
So you'll write something like
RewriteRule /search/\?.*location=([a-z0-9_.-]+)&.* geolocation=$1 [R=301,L]
I suggest also to split the configuration in two part, in order to keep the original Wordpress configuration unmodified.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /search/\?.*location=([a-z0-9_.-]+)&.* geolocation=$1 [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You need to change up your rules a little bit. This should allow you to use the new URL and also your wordpress rules.
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{THE_REQUEST} ^GET\ /search/\?location=&radius_key=([^\ &]+)&keyword=&geolocation=
RewriteRule ^ /massage/%1? [R=301,L]
RewriteRule ^massage/([^/]+)/?$ /search/?location=&radius_key=$1&keyword=&geolocation= [L]
RewriteRule ^index\.php$ - [L]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Let me know how this works for you.
Related
When I write my.domain/my/url I want to go to other webpage, but I am still on
my.domain/my/url with Error 404
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# Here is my RewriteRule
RewriteRule ^my/url$ //google.pl
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Here is the answer for your htaccess issue. You need to add the folders in the RewriteBase like i did. For example www.domain.com/my/url/ is path of your wordpress then you need to add /my/url/ to rewritebase.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my/url/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
here is Wordpress default code in .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>
What is correct way to provide only secure https connections? The code is:
RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
Is it ok the 2nd and 3rd line to put after Wordpress code to avoid duplication?
You should add that code before Wordpress, not after
# forcing SSL
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have a folder called /mf/ that is not related to the wordpress install but it is in the same root folder. When I visit the folder path (www.domain.com/mf) it gives me a 500 error. I know that this is an .htaccess issue.
I've modded my root .htaccess to do the below code but it still does not work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/mf/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
# 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 advice on how to fix this .htaccess issue?
in your "mf" folder create a .htaccess file and there put all the configuration that nedded, and in the main folder-wordpress put only the wordpress part.
in th "mf" change the RewriteBase too.
main-wordpress
# 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
the mf folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mf/
RewriteCond %{REQUEST_URI} ^/mf/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
How do you redirect a directory (in this case /resume/) to a file (/Resume.pdf) using an .htaccess file? I have tried different rewrite methods but keep getting a redirect loop. Is this because of a conflict with WordPress?
This doesn't seem to work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^resume/ http://domain.com/Resume.pdf [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Ok, I figured it out and here's what I got to work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/resume$ [NC]
RewriteRule ^(.*)$ http://domain.com/Resume.pdf [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I've got below 301 redirect the bottom one I would like to get it working but it's not working at the moment.
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^domain.com.au$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com\.au\/" [R=301,L]
RewriteRule ^author/privacy?$ privacy [R=301,L]
Is there a reason why?
I would like to redirect author/privacy to privacy...
Order of the rules is of problem here. Here is the fixed version:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com\.au$ [NC]
RewriteRule ^$ http://www.domain.com.au/ [R=301,L]
RewriteRule ^author/(privacy)/?$ /$1 [R=301,L,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Just had the same problem, but this is the answer.....
Use relative URL's not full http:// etc.
Cut the below code and add to your .htaccess file and add to your root directory
Redirect 301 /page1.php /page2.html
Redirect 301 /page3.php /page4.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>