I've been trying to redirect a page but with no success.
My purpose is to redirect example.com/me/name to example.com/me?n=name
I've tried with add_rewrite_rule, write conditions in .htaccess, but nothing worked. Any clue?
The full htaccess code is 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]

# END WordPress

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"

Edit 2:
The code for redirect I was trying to use is this:

#RewriteRule (http://example.com/me/*) http://example.com/me?n=$1

Edit 3:
The "name" in the code does not stay the same, it is variable depending on person. It can be Ash, George, Mike, whatever.

  • Can you post your .htaccess code?
    – Steve
    Jul 6 '16 at 11:18
  • @Steve - I added it in the question.
    – Vlad Nitu
    Jul 6 '16 at 11:47

use This Plugin

Or Write this code on top of htacces file:

Redirect 301 /oldfile.htm http://example.net/newfile.htm

Can you please try the following? Also make sure your Rewrite Module is "uncommented" from apache.conf and/or php.ini depending on your configuration.

#permanently redirect from example.com/me/name domain to example.com/me?n=name
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.example/me\.com$ [NC]
RewriteRule ^(.*)$ www.example.com/?n=name/$1 [R=301,L]
  • Hello and first of all thank you for trying to help me! Unfortunately it is not working, I'm not sure why myself. I posted my example commented as I decided to comment it if it's not working in order not to break something by mistake.
    – Vlad Nitu
    Jul 11 '16 at 6:34
  • About the uncomment part I mean in php.ini or apache.conf file, by default the Mod Rewrite is turned off, and if you didn't turned it on it won't work, can you tell me what's your setup like is it localhost or hosting and are you using Wampp, Xampp, Lampp etc.. Thanks!
    – knif3r
    Jul 11 '16 at 11:02
  • Hello again! I'm not sure to tell you details about the config because I work via an FTP account and the files are hosted by a company. I'm sure the mod rewrite is turned on as other redirects are working fine.
    – Vlad Nitu
    Jul 11 '16 at 13:44
  • Oh, by the way! With "name" in the link I meant to say that "name" is variable. It is like "JohnK" or "SmithA" or something like this. Not actually "name"
    – Vlad Nitu
    Jul 11 '16 at 13:46

I agree with @Kinal Nagarkar that there is a simple plugin for this. My personal Favorite is Redirection. It not only allows direct URL redirects, but also REGEX and give you a counter to monitor how often it is used. (There are also some other features that I don't personally use, but I'm sure are useful).

Either way, there are at least two plugins that you could use that are pretty light weight and don't require you to reinvent the wheel for a single redirect.

While changing your .htaccess might operate faster, please consider usability as another important factor too.

  • Hello! Thank you for the suggestion. I'd like to say that I tried using Redirection but with no success unfortunately. I didn't find much info on their page on how to use it either so I gave up trying at some point. Any chance you could point me to some information I could read and use? I'm not necessarily asking for a "ready to go" solution but at least some article or place to start reading so I can understand more about it. Thanks! P.S. I don't understand how to use it with specific parameter or RegExp
    – Vlad Nitu
    Jul 12 '16 at 7:02
  • unfortunately after some trial and error myself I found the REGEX in Redirection to be a bit wonky. I did get an error where it would replace multiple times... that was interesting. In the end I haven't found any specific documentation about how the REGEX is intended to work in this plugin. One other thing I noticed in my trials was that the plugin I tested with was hijacking some of my redirects, specifically /me/*
    – KnightHawk
    Jul 15 '16 at 13:50
  • I tried the REGEX in Redirection a bit myself and found some odd results. I tried using your me/name example but found the theme had overridden that and resulted in no effect. I tried a few others and with no good results. Apparently Redirection isn't very good (or hasn't enough documentation) for REGEX + replacement ($1) usage. But in my experience is still great for simpler redirects. Sorry this isn't much good for your exact usage.
    – KnightHawk
    Jul 18 '16 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.