Mod_write, htaccess and Wordpress slugs - wordpress

This is either blindingly simple or impossible; after lots of Googling and thread reading, I can't tell.
I have a WordPress site that uses a plugin to create a custom post type. The rub of this is that the custom post type has a very ugly "slug". What this means is that the URLs look like this:
http://mysite.org/uglyname/a-post-title/
Where "uglyname" is an ugly name. I can't change the name without editing the core files of the plugin, which is a bad idea in this context.
What I'd like to do is make it so that if a user visits a URL like this:
http://mysite.org/prettyname/a-post-title/
Wordpress interprets prettyname as it would uglyname and is more or less nonethewiser.
I don't want something that just redirects; I'd like it to be a silent mapping. But keep in mind that Wordpress is already using the .htaccess file to map everything it gets onto http://mysite.org/index.php.
Is this possible, or am I just barking up the wrong tree?
EDIT to add: The current .htaccess is the WordPress default:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite.org/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite.org/index.php [L]
</IfModule>
# END WordPress

Just above RewriteCond
%{REQUEST_FILENAME} !-f, try the following line:
RewriteRule ^prettyname/(.+)/? /uglyname/$1
If I'm not mistaken, it should pass it over, and then still process the index.php routing.
Haven't tested it - not at a server right now.

Related

htaccess query string /?

I've been searching similar examples but I was not able to find the answer in WordPress.
In google analytics I can see various string types for the same url's coming in. I looked at the htaccess file and deactivated the cache system but it's still occurring. Not sure why yet.
Now in htaccess I would like to redirect all those url's to the correct one:
Example:
// CORRECT: ...domain.com/everest-nepal/
// INCORRECT 1: ...domain.com/everest-nepal/?/
// INCORRECT 2: ...domain.com/everest-nepal/?/=
// CORRECT 3: ...domain.com/everest-nepal/?amp (this is amp related and not interested in redirecting it to the canonical url)
Is there a possible rewrite condition that could be applied in htaccess to redirect all these url's coming with this strange /?* at the end avoiding the amp?
Thanks and regards
Enric
Once you update permalinks in wordpress admin you will get .htaccess code below like this, You need to create .htaccess file in your root folder, and paste this below code, this should work,
# 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

Wordpress Problematic URL

I have a custom page in wordpress that uses a custom plugin which is connecting to an API to retrieve information.
The client has asked that we don't pass id's via the url as below:
http://beta.hirehere.co.uk/hire-vehicle-detail/?id=4
but instead use a category name such as:
http://beta.hirehere.co.uk/hire-vehicle-detail/?vehicle_category_name=economy
initially I was using a URL rewrite to pretty things up so:
http://beta.hirehere.co.uk/hire-vehicle-detail/4
and thought I would just change it to:
http://beta.hirehere.co.uk/hire-vehicle-detail/economy
I would then adjust the code accordingly. I've done this yet the URL rewrite does not seem to be happy and returns a 404 error but it works if I access the direct url of:
http://beta.hirehere.co.uk/hire-vehicle-detail/?vehicle_category_name=economy
Here is my htaccess file, any help is greatly appreciated:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^hire-vehicle-detail/(.+)$ index.php/hire-vehicle-detail?vehicle_category_name=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
PS. The above htaccess code worked in the scenario of using ID's instead
Edit: it appears wordpress is trying to access a sub-page (economy) of the parent page (hire-vehicle-detail). I know this because if I create the page economy as a child of hire-vehicle-detail the url takes me there. Is there anyway to stop this

Clean up an htaccess from infections

I have a simple wordpress website and it seems to be hacked. I used some plugins to scan it and they say my htaccess file is infected. Now I could use some help clean it up - specifically, to understand
What to look for to clean up? I.e. what does an "infection" in htaccess look like?
how can I prevent unauthorized access to the file in the future?
The htaccess in question is:
http://pastebin.com/TcWiQvNP
Here's default wordpress htaccess
# 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
also for permission
set chmd to 644
First, you need basic understanding of mod_rewrite configuration structure to understand what your current file does and be able to edit it correctly.
Now, the broadly defined redirects to some absolute URLs do look suspicious. But I don't know if the URLs correspond to your site or some other.
In general, you need to identify which directives are "alien" - i.e. do not correspond to the apps you're running at the server.

Using mod_rewrite for GET variables in a Wordpress blog page

I am working on a wordpress blog, with the default .htaccess settings:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
In my wordpress blog, I have created a page called "mypage". Using my rewrite settings, it is shown in the address bar as http://www.mysite.com/mypage.
I am using a custom page template and am processing some things, which include the use of GET variables. For instance:
if (isset($_GET='word')) { echo $_GET['word]; }
So, http://www.mysite.com/mypage?word=dog will display "dog".
The problem I am having is rewriting the URL so that it can look like: http://www.mysite.com/mypage/dog, still being able to access "dog" as the GET variable.
I am not too good with mod_rewrite rules to begin with, but working from within a wordpress installation is throwing me an extra curveball.
Does anyone know what I need to add to my .htaccess to achieve this?
Thank you!
Try the following:
RewriteRule ^mypage/([^/])/?$ mypage?word=$1 [L,QSA]
The L flag instructs .htaccess to stop processing rules, and QSA appends the query string since you might have other GET parameters on the end of the URL.
Mod_Rewrite Documentation

404 keeps kill me after Wordpress 3.0 and higher

what have you done since Wordpress v3.0, all direct PHP files are not working in WP, all are returning 404 page not found, I have created one plugin, it's loading /wp-content/plugins/myplugin/direct.php file and what am I seeing now, it shows me my WP site with title PAGE NOT FOUND 404, help me please I can't work with WP any more, all direct PHP files are not accessible and tracked as 404.
What should I do to turn off that terrible 404 or get my php files loaded.
Check your .htaccess file, maybe all URLs now are mapped to the index.php file of Wordpress.
Based on the provided rewrite rules, I would suggest to use this instead:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*shop/images/(\d+)/?\??(.*)$ /wp-content/plugins/shopp/core/image.php?siid=$1&$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I'm not understanding the question. You're saying that you've created a plugin, and it's not calling in the files properly? (I'm assuming by "direct PHP file access" you mean you can't load a particular file that's within your plugin directory?)
Sounds like you're not using the correct paths. You should be using things like WP_PLUGIN_URL constants that are set up for you via WordPress (http://codex.wordpress.org/Determining_Plugin_and_Content_Directories) - i.e it doesn't sound like an .htaccess issue, it sounds like improper coding in the plugin.
Of course, without knowing what code you are using, it's difficult to say what the issue could be.

Resources