I'm having a problem with my URL and my sessions.
I wish to have ALL website pages be forced to use www. As it looks like now, the website looks like this:
www.example.com into www.example.com
example.com into www.example.com
www.example.com/example/ into www.example.com/example/
example.com/example into example.com/example (this is what's wrong)
This is what my .htaccess file looks like:
# 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]
RewriteCond %{HTTP_HOST} ^wewent\.net
RewriteRule ^(.*)$ http://www.wewent.net/$1 [L,R=301,NC]
</IfModule>
# END WordPress
Because the URL does not redirect properly I get double up with sessions one for www and one for the website without. How can I prevent this the best way?
It seems to look ok but one thing you should do is always put your other rules before the wordpress rules as a habit. When using wordpress it should generally be the last set of rules since it does all the routing. Now for the redirect, you should probably use 302temporary which will remove any current cache and verify that your redirects are working properly. Then you can change it to 301 for permanent once it's working correctly.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.wewent\.net [NC]
RewriteRule ^(.*)$ http://www.wewent.net/$1 [L,R=302,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Related
Here is our current .htaccess file with the rules we need to keep but also we need to add a new rule that redirects from the root domain to a subfolder URL
example.com -> example.com/fl/en.html..
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.nz$
RewriteCond %{REQUEST_URI} !^/subfolder [NC]
RewriteRule ^(.*)$ /subfolder/$1 [L]
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(/home.html|/info.html|/flash|/external)
RewriteRule (.*) http://example.com/fl/en.html [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
There doesn't appear to be anything particularly special required, providing you put the directive in the correct place. To redirect the document root (for example.com) to /fl/en.html in .htaccess can be done like so:
RewriteRule ^$ /fl/en.html [R,L]
This just needs to go after the directive that rewrites everything for the host domain.co.nz and before your front-controller. (You could potentially combine this with your existing directive that redirects /home.html, /info.html, etc.)
Your existing rules could be further optimised. Instead of checking the requested URL-path in a RewriteCond directive and allowing everything through in the RewriteRule pattern, it is more efficient to do what you can in the RewriteRule pattern first (since this is what is processed first).
Also, since you are using WordPress, any custom directives you add to .htaccess should be outside of the # BEGIN WordPress section. WordPress itself maintains this section, so any manual customisations you make could be overwritten during an update.
Also, there is no need to repeat the RewriteEngine directive. (The last instance of this directive wins and controls the entire file.)
So, bringing all this together, we have something like:
# Rewrite all requests for domain.co.nz to subfolder
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.nz$
RewriteRule !^subfolder /subfolder%{REQUEST_URI} [L]
# Redirect document root to /fl/en.html
RewriteRule ^$ /fl/en.html [R,L]
# Redirect specific paths to /fl/en.html
RewriteRule ^(/home.html|/info.html|/flash|/external) /fl/en.html [R=301,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
Note that the above directive (with a single R) is a temporary (302) redirect. Change this to R=301 if this is intended to be permanent, but only once you have tested that it's working OK (to avoid caching issues).
As always, make sure you've cleared your browser cache before testing.
I'm trying to make it so that anything at /about goes to /our-story.
I think my .htaccess redirect rule is correct for 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]
The line is here:
RewriteRule ^about.*$ http://domain.com/our-story/ [R=301,L]
</IfModule>
However it doesn't seem to work. My suspicion is that this is due to Wordpress being active. I tried to put it inside the Wordpress block though, and still it doesn't work.
What do I have to do to redirect from /about to /our-story?
The rule is correct, but they need to go before the wordpress rules because you are redirecting while the wordpress rules routes everything into /index.php. Any request URI that starts with /about will end up getting routed to wordpress and thus never get redirected. Just switch the order:
RewriteRule ^about.*$ http://domain.com/our-story/ [R=301,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>
I tried googling this problem about a site do not open without www in chrome, But it works on other browser, here's my .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mydomain\.com\/$1" [R=301,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
You have mistake in your .htaccess file. You activate rewrite engine twice. Your .htaccess file has to be like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mydomain\.com\/$1" [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Update:
You can't open your site in chrome without www. because your .htaccess file contains redirection rule, what redirects your visitors from mydomain.com to www.mydomain.com. This rule is used for SEO, read through Redirection SEO Best Practices article (especially Redirecting Canonical Hostnames paragraph) to become more familiar with it.
I have a blog set up at blog.ftj.com/ACSM, it is hosted with Bluehost and their folder structures seem to be case sensitive. Is there something in the .htaccess file that I can adjust so that all possible combinations get redirected to the specific uppercase URL.
Another issue is that it seems that I need to redirect
blog.ftj.com/acsm/
with and without the forward slash.
Here is my current .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ACSM/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ACSM/index.php [L]
</IfModule>
# END WordPress
Please submit the full change if you would.
You need to place the following .htaccess in the root dir to rewrite all requests to /ACSM into /acsm
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/acsm$ [NC]
RewriteRule ^(.*)$ /ACSM [L]
RewriteCond %{REQUEST_URI} ^/acsm/(.*)$ [NC]
RewriteRule ^acsm/(.*)$ /ACSM/$1 [L]
</IfModule>
Sorry for delays, have not got an Apache at hands....
I need a general rule that maps every URL in the /beta subdirectory to the corresponding URL in the root; essentially I need to remove /beta from all URLs.
In case it makes any difference, the URLs are dynamically generated by WordPress.
Currently my .htaccess file is:
# 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
Can you tell me where to put the new lines?
Thank you!
Could you try this?
RewriteEngine On
RewriteRule ^beta/(.*)$ http://example.com/$1 [R=301,L]
Your question is not entirely clear, but I would bet that what you want is having a Wordpress installed in somedir/beta appear in yoursite.com/ instead of yoursite.com/beta/. The rules you pasted are in somedir/beta/.htaccess, and are the default Wordpress rules. You must leave those alone.
What you need for that is to put the following rules in the root directory, as in, somedir/.htaccess, after changing example.com to your own domain. Your webserver first reads this root .htaccess, and when it does, it will know to rewrite requests to /beta.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/beta/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /beta/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ beta/index.php [L]
</IfModule>
More info in the Codex:
https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory