Hot answers tagged

32

Add this to your theme's functions.php, or put it in a plugin. add_action( 'init', 'wpse26388_rewrites_init' ); function wpse26388_rewrites_init(){ add_rewrite_rule( 'properties/([0-9]+)/?$', 'index.php?pagename=properties&property_id=$matches[1]', 'top' ); } add_filter( 'query_vars', 'wpse26388_query_vars' ); function ...


9

Check out the Roots WordPress Theme. They seem to do exactly what you want with the URLs. Here's a snippet from their roots-htaccess.php file: add_action( 'generate_rewrite_rules', 'roots_add_rewrites' ); function roots_add_rewrites($content) { $theme_name = next( explode( '/themes/', get_stylesheet_directory() ) ); global $wp_rewrite; $...


6

Hi @NetConstructor: Well if I had thought about how much work with was going to be before writing it, you wouldn't be able to get me points right now. :) Needless to say, it's rather involved (though I don't think it really should have to be, but it is what it is.) First off, you can't (easily) do it like you wanted; the problem is how to differentiate ...


6

You can also set a custom variable inside WordPress when your URL is accessed. You can then later check for this variable and if it exists, do whatever you want to do. In this example, we will use wpse6891_stats as our variable. // Register a URL that will set this variable to true add_action( 'init', 'wpse6891_init' ); function wpse6891_init() { ...


6

If the issue is only with images, but not css or javascript, I think there's a typo in your RewriteRule. I think your missing a "1" after the "$": RewriteRule ^images/(.*)$ wp-content/themes/standard/images/$1 [L] Also, you might want to try putting those extra statements below the initial rule, ie below this line: RewriteRule ^index\.php$ - [L] Not ...


5

Mark, I hate to say it, but you're going about this the wrong way. PHP files in your plug-in should never be accessed directly in this way. Instead, they should be loaded from within WordPress just like everything else. Here are some alternative paths you could take: Create an admin page that displays your stats This is a page accessible from within ...


5

Problem solved. The plugin "User Access Manager" was found guilty of inserting a .htaccess file into wp-content/uploads/ and not handling calls properly afterwards. I don't know how UAM plugin could be fixed, but It's ok to remove the .htaccess file. Nothing else depends on it. (at least in my case)


5

Why don't you create a shortcode for that in the following manner. function img_folder_shortcode( ) { return get_stylesheet_directory_uri() . '/images'; } add_shortcode( 'img_folder', 'img_folder_shortcode' ); And then use the following shortcode anywhere in the content area. [img_folder]/img.jpg <img src="[img_folder]/img.jpg" alt="img" />


5

Have a read of the following thread on the WordPress forum, apparently the AddThis plugin is the reason the hash tag is been appended to the URL. http://wordpress.org/support/topic/random-hashtag-strings-added-to-url-in-firefox


5

You'll find this post by Joost De Valk on changing WordPress permalinks to only include /%postname% very helpful. How many posts you have doesn't matter anymore if you are using the latest version of WordPress (at least > v3.3.1). I believe your permalink structure initially was — this /blog/%year%/%monthnum%/%day%/%postname%/ — and now, you are planning ...


4

you need 3 simple functions and hooks first change the author base: //change author/username base to users/userID function change_author_permalinks() { global $wp_rewrite; // Change the value of the author permalink base to whatever you want here $wp_rewrite->author_base = 'users'; $wp_rewrite->flush_rules(); } add_action('init','...


4

You don't have to touch the Apache configuration for this, you can do this all from the WordPress rewrite system. But indeed, your general idea is correct: you should append ?cat=3 (or category_name=blog if you want to be even clearer). Remember that your blog archive can have multiple pages, maybe you want to handle this too. This is how I would do this ...


4

The output of $_SERVER['SERVER_SOFTWARE'] is WebServerX That looks like your problem - check out this line in wp-includes/vars.php: /** * Whether the server software is Apache or something else * @global bool $is_apache */ $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false)...


4

In theory, you could rename the file and change the rewrite rule accordingly. Assuming you rename it to wp-index.php, it would look something like this: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wp-index.php [L] </IfModule> There are a few ...


3

WP rewrite rules are not real rewrites nor will they allow redirects like that. So you can't use them that way. Fortunately, WP should have you covered there even if you try. See, an internal WordPress rewrite rule must change a URL pattern into an index.php?key=value pattern. So when you use add_rewrite_rule to insert a rule that doesn't point to the ...


2

No, index.php file is present and used in WordPress (source). Depending on what existing homepage is it can be renamed to another non-conflicting file or migrated to WordPress.


2

Alternatively you can add the following line of code to your functions.php file: add_filter( 'got_rewrite', '__return_true', 999 ); We're doing this to make WordPress play well with nginx.


2

'RewriteBase /' is not needed. RewriteBase allows you to change your internal directory structure to something other than what a browser sees. IE: If all your files are in 'http://mydomain.com/site', but you wanted 'http://mydomain.com' to be the path browsers see, you would use a RewriteBase /site and apache's mod_rewrite would happily add that substitution ...


2

Inside of your config you have the following: <Directory /> Options FollowSymLinks AllowOverride None </Directory> You should change it to the following: <Directory /> Options FollowSymLinks AllowOverride All </Directory> The AllowOverride directive is what allows the .htaccess file to be read. If you still have ...


2

The URL hash (everything after the #) does not get sent to the server, so Apache or WordPress can't detect it. WordPress redirects all URLs to the canonical version of the URL, to make sure everyone uses the same URL when linking to a post (which can help increase your ranking in search engines). This causes a redirect from /faqs to /faqs/. Browsers should ...


2

If your permalink structure is /%postname%/ with a trailing slash, you need to pass the hash like this: /faqs/#b with the trailing slash.


2

yes, this: https?://yoursite.com doesn't do anything you want, just make it http://yoursite.com. Next to that, make sure your server actually supports RedirectMatch.


2

You should look at "Rewrite Endpoints", which are much simpler to work with than custom rewrites. And they fit your use case perfectly: http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint You might add your "show" endpoint like so: function wpsx_37961_add_endpoints() { // Add the "show" rewrite endpoint to all URLs add_rewrite_endpoint('...


2

The best way to accomplish this is remove the default sanitize_title filter and replace it with yours, which will encode those characters properly. Here is an implementation of using accents in permalinks. Example: remove_filter( 'sanitize_title', 'sanitize_title_with_dashes'); add_filter( 'sanitize_title', 'restore_raw_title', 9, 3 ); function ...


2

When you register your post type, the with_front argument of rewrite should be false, so the permastruct is not appended to the front of your custom post type permalink. $args = array( // snip... 'rewrite' => array( 'with_front' => false ), // snip... ); register_post_type( 'your-post-type', $args );


2

I did not test this, but this should do what you want. Put the following in your functions.php: add_filter('rewrite_rules_array', 'new_category_name_rewrite_rule'); function new_category_name_rewrite_rule($rules) { $new_rules = array(); $categories = get_categories(); foreach ($categories as $category) { $cat_name = preg_replace('#\s+#', ...


2

This should cover everything: function wpa_rewite_translate(){ global $wp_rewrite; $wp_rewrite->pagination_base = 'pagina'; $wp_rewrite->author_base = 'autor'; $wp_rewrite->comments_base = 'comentarios'; $wp_rewrite->feed_base = 'alimentar'; $wp_rewrite->search_base = 'busqueda'; $wp_rewrite->...


2

Judging from other threads, here are the two most common causes of this problem on freshly built servers: .htaccess override is disabled by apache2.conf Apache mod_rewrite module isn't enabled. In the file /etc/apache2/apache2.conf: <Directory /var/www/> AllowOverride All </Directory> "AllowOverride" is the switch that tells Apache ...


2

You can add a RewriteRule to your .htaccess to instruct mod_rewrite to stop processing any URI that begins with Staff/ or resolves to Staff: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteRule ^/?Staff(/|$) - [END,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-...



Only top voted, non community-wiki answers of a minimum length are eligible