An multilanguage wordpress site has multiple prefixes for languages (si,en,de,...)
1. https://www.example.com
2. https://www.example.com/porfolio/images
3. https://www.example.com/en
4. https://www.example.com/en/porfolio/images
Is there an .htaccess script, that would rewrite links 1,2 to 3,4 without changing the url?
My current script returns too many redirects, because of an apparent loop.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/en/
RewriteRule ^(.*)$ /en/$1 [L]
Related
I have site with 2 other sites in subfolders
https://example.com/
https://example.com/demo1
https://example.com/demo2
All 3 sites are actually wordpress installations.
The problem is: when I opened a page
https://example.com/demo1/testpage
I got redirected to
https://example.com/testpage
Contents of example.com/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've tried to add one more RewriteCond before RewriteRule (one line at a time):
RewriteCond %{REQUEST_URI} !demo1
RewriteCond %{REQUEST_URI} !^/demo1/(.*)$
RewriteCond %{REQUEST_FILENAME} !demo1
RewriteCond %{REQUEST_FILENAME} !^/demo1/(.*)$
But none of this worked.
So how to make it work and avoid redirect?
It's very strange but solution was to resave site url in wordpress settings on /demo1/wp-admin/options-general.php
Have searched and applied many of the rewrite rules available but no avail,
I am trying
http://website.io/paypal should go http://www.website.io/paypal
but it simply goes to www home page http://www.website.io
should be the same for https. Or at lest non-www redirects to https://www.website.io/paypal is fine, but should carry the page name.
after many trial and error versions here is the closest one I have got which isn't working good
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# WordPress Defaults
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
UPDATE
It seems nothing wrong with redirection though, www and non www domains were mapped to different ips thus not found on non-www urls.
Here is your exact working code. This will redirect you to your desired page perfectly.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI}paypal [R=301,L]
# WordPress Defaults
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Note: Only this below line has some minor change otherwise you have done great job.
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI}paypal [R=301,L]
Let me know if it solves your issue ?
I looked at this: htaccess remove index.php from url but it didn't work and in the comments there seems to be disagreement on the top answer.
If I type in http://www.example.com/thanksgiving/index.php/getThankyou I get the page I want served.
If I type in http://www.example.com/thanksgiving/getThankyou I get a 404.
What I've tried in my htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/thanksgiving/(.*)/$ /thanksgiving/index.php/$1 [L]
</IfModule>
How do I do it so /thanksgiving/getThankyou/ or any url starting with /thanksgiving in the url leads to the proper resource being served? Again, it is currently available when index.php is in the url.
I also tried: RewriteRule ^/thanksgiving/[^/]*/$ /thanksgiving/index.php/$1 [L] but that didn't work either...
Edit: It seemed part of the htaccess is being set by wordpress and may be conflicting with the desired behavior above:
The wordpress part of the same htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Is this interfering? How do I reconcile this with the /thanksgiving/ urls which are not part of the Wordpress application?
Edit:
The above only pertains to the root (public_html) htaccess, below is the htaccess in /thanksgiving/ itself, please analyze for conflicts, thanks for all your help!
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
# Do not change this line.
# Change example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change your_app_name to the subfolder name
RewriteCond %{REQUEST_URI} !^/thanksgiving/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change your_app_name to the subfolder name
# Change example.com to your domain name
RewriteRule ^(.*)$ /thanksgiving/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ thanksgiving/index.php [L]
You need to remove the leading slash from your rewrite pattern :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:thanksgiving/)?(.*)$ /thanksgiving/index.php/$1 [L]
</IfModule>
Otherwise the rule will accept the uri starting with a double leding slash (ie : //thanksgiving/ ) .
I moved a Wordpress blog from blog.mywebsite.com to mywebsite.com/blog/ .
Everything was OK until I tried to redirect old links to the new location.
I want people asking http://blog.mywebsite.com/2014/09/article-example/ to find themselves in http://mywebsite.com/blog/2014/09/article-example/
But the htaccess is already completed with some rules using the keyword "blog"
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
I cannot find the way to write the rule
Today I have an error 500 with this link : http://blog.mywebsite.com/2014/09/article-example/
I would like at least to redirect to mywebsite.com/blog/ , ideally to http://mywebsite.com/blog/2014/09/article-example/
Any idea?
Thanks and good day everyone :)
You can replace your current htaccess code by this one
RewriteEngine On
RewriteBase /blog/
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/blog/$1 [R=301,L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
# 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
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.app.domain.com$
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule (.*) /app/$1
RewriteCond %{HTTP_HOST} ^app.domain.com$
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule (.*) /app/$1
The problem: app.domain.com is working without problems, but as soon as you add a subfolder like app.domain.com/folder you get the Wordpress tag page.
What am I doing wrong?
The problem is here
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule (.*) /app/$1
Which says that if the URL does not start with /app/ (which /folder doesn't) it must be rewritten to /app/folder. After that rewrite the RewriteRules will be processed again, and the wordpress section will find that folder doesn't exist and fire up wordpress for you.
The way to resolve this issue is to change the last block to
RewriteCond %{HTTP_HOST} ^(www\.)?app\.domain\.com$
RewriteRule %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule .? app%{REQUEST_URI} [L]
This tells apache it may only rewrite to /app/folder if /folder does not exist.
(and you can remove the whole stuff for app.domain.com, this block handles both www.app.domain.com as well as app.domain.com