I have a question about rewriting WordPress URLs.
Currently when I go to https://example.com/product/foo/ I get product information.
I would like to make it so that when https://example.com/product/foo/en/ is accessed, the information on https://example.com/product/foo/ is displayed.
I tried to do this with .htaccess, but I couldn't figure it out at all.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /product
RewriteCond %{REQUEST_FILENAME} ! -f
RewriteCond %{REQUEST_FILENAME} ! -d
RewriteRule (. *)/en/$ (. *)/ [L]
</IfModule>
I would like https://example.com/product/foo/ to be the native language page and https://example.com/product/foo/en/ to be the English page.
I would appreciate it if someone could tell me more about this.
Related
I have a wordpress site eg. http://www.domain.com/ with custom theme hosted on a linux server and working fine. Some marketing strategy requires me to distinguish between 2 kinds of URLs (that they will be shooting from ads) and based on that redirect the site to different links.
eg:
If the URL contains /xyz/ ie:
http://www.domain.com/xyz/category/post I want it to be redirected to
an intermediate page ie: http://www.domain.com/intermediate.php and if
the url doesnt contain /xyz/ ie:
http://www.domain.com/category/post the post should show up as
usual.
I found out that this cant be done inside the wordpress code as before the first hook is triggered, the url is processed and a 404 page is thrown.
The only way I can achieve this is by modifying .htaccess file.
I found a code which reads:
RewriteRule ^(.*)/xyz/(.*)$ http://www.domain.com/intermediate.php [L,R=301]
and second way reads:
RewriteCond %{REQUEST_URI} /xyz/
RewriteRule .* http://www.domain.com/intermediate.php
I am really confused about using it with the existing code in the htaccess file created by wordpress which reads:
# 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
I tried merging the codes ie:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /domain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /domain/index.php [L]
RewriteCond %{REQUEST_URI} /xyz/
RewriteRule RewriteRule ^(.*)/xyz/(.*)$ http://domain.com/intermediate.php
</IfModule>
but only one of them work at a time ie: when the redirection works, wordpress posts doesnt show up and vice versa.
Kindly show me a better way.
Immediately after the RewriteEngine On and RewriteBase directives in the "existing" WordPress code try this:
RewriteRule xyz/ http://www.domain.com/intermediate.php [L,R=301]
This will search for "xyz/" anywhere in the requested URL and redirect when found. Note that in .htaccess files, the directory prefix (/ in this case) is removed from the URL path before pattern matching. So, a pattern that starts / will never match at the start of the URL.
External redirects should generally come before internal rewrites, which is what the default WordPress directives do.
The alternative method you mention is less efficient:
RewriteCond %{REQUEST_URI} /xyz/
RewriteRule .* http://www.domain.com/intermediate.php [R=301,L]
This will effectively do the same thing but will result in every request being processed because of the generic .* pattern. Note that the REQUEST_URI does start with a / (directory prefix).
I've got an url /nl/sunglasses which is a translated page by qtranslate. I want to change this to /zonnebrillen . I prefer not to change this in wordpress since the 'sunglasses' is generated by a plugin wp-ecommerce and hardcoded.
Can I use a mod_rewrite so that /nl/sunglasses will be /zonnebrillen. And how can I let wordpress 'know' to show the according page?
Cheers!
Here's some code I modified after getting WP to take query vars in the URL including "name" as a query var. I am including the "original" .htaccess file posted by regular WP install to show the context. I have separated the rewrites to avoid problems when WP updates, or when "certain admin functions" cause it to change. P.S. I didn't test this, but similar code works for a much more complex page redirect... so try it. Let me know if it doesn't work for you, I'll test it.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^nl/sunglasses/ /zonnebrillen [NC,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
Should work with WP 3.4+
This is my htaccess for 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
I create a category named "hotels"
I like to change my url via mod rewrite apache module.
My current url like this
http://www.mydomains.com/hotels?state=newyork&country=us
But I want url like below:
http://www.mydomains.com/hotels/us/newyork
How can i achieve this?
I tried to get url like this:
http://www.mydomains.com/hotels/newyork from http://www.mydomains.com/hotels?state=newyork
so i used this line after the rewrite rule but it was not worked.
RewriteRule ^hotels/([^/]*)$ /hotels/?state=$1 [L]
Can some one please help me?
Thanks in advance
Is there a particular reason you are trying to change permalinks via htaccess? This is more effeciantly done thru the wordpress dashboard under
Settings> Permalinks
You can choose a custom permalink structure or choose from the pre selected ones given thru wordpress.
Put this before the RewriteConds:
RewriteRule ^hotels/([^/]+)/?$ hotels?state=$1
You don't want the [L] flag because it prevents Wordpress from ever processing it.
I'm trying to redirect a few pages to different pages. This should be simple, but I'm missing something simple, apparently.
I have a wordpress install on a subdomain. Wordpress's generic htaccess 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]
</IfModule>
# END WordPress
I want to redirect /farm-partners/ to /farm-partners/emilys-produce/. I'm trying to do so using the following code:
RewriteRule ^farm-partners/?$ /farm-partners/emilys-produce/ [L]
However, opening /farm-partners/ doesn't redirect, it just loads that page. What am I missing?
Use the WordPress Redirect plugin and don't mess with the htaccess.
What you are missing in your RewriteRule though, it telling it that you want an external redirect
RewriteRule ^farm-partners/?$ /farm-partners/emilys-produce/ [L,R=301]
If you use a RewriteRule, make sure it is outside the comments that indicate which parts of the file may be edited without any notice (i.e. outside the #comments marking WordPress's section of the file. Similarly if you are using W3 Total Cache or a similar plugin.)
Try this:
RewriteRule farm-partners/$ /farm-partners/emilys-produce/
I'm using Wordpress with a plugin and it's currently making urls like this: http://www.example.com/?name=the-office
I would like to redirect all similar urls to http://www.example.com/name/the-office
Current 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
I tried a few things and nothing seemed to work, maybe I'm need to place the RewriteCond in the IfModule? Not sure, htaccess is foreign to me. Thanks in advance.
If you'd like a workaround that is much easier to accomplish - simply login to your wordpress admin panel, go to settings, then permalinks and there you can select how your links will look like. Select the last option (Post name) to get only post names in the urls.