Redirect URL with mod_rewrite with variable - wordpress

I am looking to get a rule setup to change one of my URL's. After much research I understand the basics of mod_rewrite. The trouble I am having is the dynamic URL that is being re written. I have outlined in as much detail possible the task and desired outcome.
I currently have a url that looks like this:
http://www.myndness.com/my-canvas/{username}/
The {Username} is variable depending on which user you click on.
What I need to do is add /?my_posts to the end of that URL. This will then display the posts module by default for all users.
So all the users will follow the same URL pattern:
/User1/?my_posts
/User2/?my_posts
/User3/?my_posts
/User4/?my_posts
Apologies if I have missed anything.
I am using WordPress and have access to all files on the server.

Try this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^my-canvas/[^/]+/?$ $0?my_posts [R=301,L,NC]

Related

I want to block a certain url, what kind of condition do I have to write in .htaccess

There's a critical security breach in Revolution Slider, a plugin for WordPress. It works by accessing a certain URL that let's download the config files eg.
www.domain.com/wp-admin/admin-ajax.php?action=revslider_show_image&img=../wp-config.php
I've been trying to make a rewrite condition so that url wouldn't be accessible anymore. This is what I have now in my .htaccess file
RewriteEngine on
RewriteCond %{QUERY_STRING} ^action=revslider_show_image&img=(&.*)?$ [NC]
RewriteRule ^wp-admin/admin-ajax\.php$ /?%1 [R=301,NE,NC,L]
but it doen't work, I'm not very familiar with rewrites, any suggestions on what I'm doing wrong here?
Instead of redirecting to protected file, you should forbid it (with F flag, equivalent to 403).
Also, you have an error in your condition's pattern.
Put this code in your htaccess before Wordpress' main rule
RewriteCond %{QUERY_STRING} ^action=revslider_show_image&img=[^&]*$ [NC]
RewriteRule ^wp-admin/admin-ajax\.php$ - [F]
Justin's answer will work and directly answers your "how do i" question, BUT...
This will prevent Rev Slider from working entirely, since you're forbidding the ajax call which is used to get and display an image.
I know you're looking for a quick fix until you get the plugin updated (which I did confirm myself today, patching to 4.6 works just fine), but be careful about HOW you're doing it. The best thing for you to do is update the plugin, not to implement this.

How to rewrite URL in wordpress

I am facing some issue with url rewrite for wordpress
I have URL like this:
http://example.com/mentor-profile/?mentor_slug=dr-jonathan-fass
http://example.com/mentor-profile/?mentor_slug=neha
This is not user and SEO friendly, I want URL like this:
http://example.com/dr-jonathan-fass
http://example.com/neha
I am doing change in .htaccess file but something going wrong. Thanks.
Basically, Wordpress allows you to use SEO and user friendly URLs, just change your permalink settings in Administration area -> Settings -> Permalinks and set them to Post name.
More information - here.
You can use wordpress plugin to edit url whatever you want like below:
http://wordpress.org/plugins/custom-post-type-permalinks/
Or search another on the same site which suits to your requirement
The desired redirects could work for example like this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)&?mentor_slug=([^&]+)&?(.*)$ [NC]
RewriteRule ^/?(.*)$ /%2? [R=302,L]
Anyway, you should also define other cases, like:
Is it possible, that there are folders before the parameter? What should happen for example in the following case:
http://example.com/mentor-profile/test/asd/albala/?mentor_slug=dr-jonathan-fass
Should these folder be kept or be cut?
What should happen, if there are any other parameters, for example:
http://example.com/mentor-profile/?test=asd&ala=balab&mentor_slug=dr-jonathan-fass&hi=hello
Should other parameters be kept or be lost?

Rewrite/redirect aspx with specific quesry string to specific wordpress page

I've searched through and can't find a working solution...
I've ported a site from asp.net to php. As instructed, I left the internal links as .aspx for seo. For static pages outside wordpress, with no query string, I can work it fine:
RewriteEngine on
RewriteRule ^testimonials.aspx$ /testimonials.php [NC,R=301]
But, I have some links which include query strings... These links now have to point to pages that are currently inside a wordpress installation. How can I get
myawesomesite.com/catalog.aspx?n=My%incredible%20product
to redirect to
myawesomesite.com/catalog/my-new-incredible-product/
AND
myawesomesite.com/catalog.aspx?n=My%other%20product
to redirect to
myawesomesite.com/catalog/my-new-other-product/
etc... (in the destination, 'catalog' is the directory that wordpress is installed in)
I've tried all kinds of things but am no expert. I know I need to do something to get apache to catch the query strings...
I'll give this a go the below should do it:
RewriteCond %{QUERY_STRING} ^n=My(?:[\ +]|%20)incredible(?:[\ +]|%20)product$ [NC]
RewriteRule ^catalog\.aspx$ http://www.myawesomesite.com/catalog/my-new-incredible-product/? [R=301,NE,NC,L]
Just amend the parts to match your other URL
I have always found this tool to be useful for redirects
http://seo-website-designer.com/HtAccess-301-Redirect-Generator

MVC urlHelper.RouteUrl to provide the full path on the server

I'm currently doing something in OrchardCMS we're using URLRewrite so that if a user comes to the site from site.com or from site.com/orchard, they get the site.com/orchard page.
One of the problems is that it's throwing the urls in the menu because it's using urlHelper.RouteUrl which uses the wrong context and then produces a url like site.com/page1 rather than site.com/orchard/page1. Is there either a way to tell urlHelper.RouteUrl to start from a different page than the current one, or to get the function to return the full path?
Thanks
Maybe you could use the Orchard Rewrite module where you can define redirect rules like this:
RewriteCond %{REQUEST_URI} !^orchard [NC]
RewriteRule ^(.*)$ /orchard/$1 [R=301,L]
Try setting up your application under site.com/orchard virtual directory and then use UrlRewrite in IIS to do appropriate 301 redirect when user enters site.com. This is a much cleaner approach.
HTH

mod_rewrite redirect for site that contains drupal

I am new to using mod_rewrite, so I need an explanation in simple terms. I'm trying to do a redirect for a directory that is in the same directory as a Drupal installation but is not part of Drupal.
For example, a file used to exist at http://mysite.com/events/listen/song.mp3. I rearranged so that the file now resides at http://mysite.com/listen/song.mp3.
I can use the following in mod_rewrite and it works:
RewriteRule ^events/listen/(.+)$ listen/$1 [NC]
However, I'd like to do a real redirect, so that the user sees the new URL instead of the old one. I've tried:
RewriteRule ^events/listen/(.+)$ listen/$1 [R,NC]
and
RewriteRule ^events/listen/(.+)$ http://mysite.com/listen/$1 [R,NC]
Neither of these work. I think it probably has to do with all the rerouting that Drupal is doing, though I do have my rewrite rules before Drupal's in .htaccess. Is there something obvious I'm missing? Or is there a way to allow this to work without messing up what Drupal is doing?
Try
RewriteRule ^events/listen/(.+)$ listen/$1 [R=301,L]

Resources