Combine 2 .htaccess Files - wordpress

I have 2 .htaccess files that I need to merge together. One is generated by wordpress and the other is the existing .htaccess file for the site. The 2 files are as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=301]
RewriteRule ^postreview/$ /viewreview.php [NC,PT,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ ./template2.php
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
php_flag session.use_trans_sid off
2nd file generated by wordpress:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projectcars/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /projectcars/index.php [L]
</IfModule>
I've tried several ways to combine them, but I either get a redirect error or a internal server error.

Here's my fix:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^postreview(\/?)$ /viewreview.php [QSA,NC,PT,L]
RewriteRule ^projectcars/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^projectcars/(.*)$ /projectcars/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) template2.php [NC,L]
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
php_flag session.use_trans_sid off

Related

RewriteRule Apache Directives in .htaccess not working

My .htaccess file for my PHP wordpress app is in clone-directory/php/ and I could say that it was recognized by the OpenShift server. But some of the RewriteRules and RewriteCond doesn't seem to work. Since the app is accessible by both http and https by crawlers, I'm trying to create separate robots.txt for ssl and http connections.
I've been researching hours and hours with several different codes but none of them work. Some of them are as follows ...
1
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^robots.txt$ robots-https.txt [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
2
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^robots.txt$ robots-https.txt [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
3
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^robots.txt$ robots-https.txt [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
4
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} ^on$ [NC]
RewriteRule ^robots.txt$ robots-https.txt [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
5
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^robots.txt$ robots-https.txt [L]
When I visit https://reversiblean-reversiblean.rhcloud.com/robots.txt, the url won't redirect. URL is always the same.
Keep it like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^robots\.txt$ /robots-https.txt [L,R,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Make sure the robots.txt and the second robots.txt exist in the repo's php directory. Unlesss OpenShift will point it to a default robots.txt, though I'm not sure where that file is stored. I was expecting for the url to change, but only the contents of the robots.txt would change according to the http protocol.
I can't believe I've spent almost half of my day on this. : )
In case anyone else was having trouble or wondering about Google's duplicate content issue, here's how my .htaccess looks now ...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteRule ^robots.txt$ robots-ssl.txt [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

404 specific image error for a directory (symlink)

I am trying to serve a specific jpeg picture that depends on the directory.
For example:
/i/t/150/63211.jpg => /i/404/150.jpg
/i/t/195/63211.jpg =>/i/404/195.jpg
At the moment, even something simple (one rule at a time) like :
RewriteCond %{REQUEST_URI} ^/i/t/150/.*\.jpg
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^.*$ /i/404/150.jpg [L]
Doesn't work even if my jpeg file is in the directory /i/404/.
I think the problem comes from the fact that /i/ is a symlink.
My goal is to have the 2 rules (for 150.jpg/195.jpg) in the same RewriteRule. But let's try to make it work with one only.
Here is my full htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-a([0-9]+)\.html$ 301oldninapeople.php?oldid=$2&section=news [L]
RewriteRule ^(.*)-n([0-9]+)\.html$ 301oldninapeople.php?oldid=$2&section=theme [L]
RewriteRule ^(.*)-n([0-9]+)-page([0-9]+)\.htm$ 301oldninapeople.php?oldid=$2&section=theme [L]
RewriteRule ^301oldninapeople\.php$ - [PT,L]
RewriteCond %{REQUEST_URI} ^/i/t/150/.*\.jpg
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^.*$ /i/404/150.jpg [L]
RedirectMatch 301 ^/rss/news.(xml|asp)$ /feed
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [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
Current robots.txt after the first answer:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^i/t/([^/]+)/.+?\.jpg$ /i/404/$1.jpg [L,NC,R]
RewriteRule ^(.*)-a([0-9]+)\.html$ 301oldninapeople.php?oldid=$2&section=news [L]
RewriteRule ^(.*)-n([0-9]+)\.html$ 301oldninapeople.php?oldid=$2&section=theme [L]
RewriteRule ^(.*)-n([0-9]+)-page([0-9]+)\.htm$ 301oldninapeople.php?oldid=$2&section=theme [L]
RewriteRule ^301oldninapeople\.php$ - [PT,L]
RedirectMatch 301 ^/rss/news.(xml|asp)$ /feed
# RedirectMatch 301 ^/rss/news.xml$ /feed
# RedirectMatch 301 ^/rss/news.asp$ /feed
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [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
You just need this rule:
RewriteCond %{DOCUMENT_ROOT}/$0 -f
RewriteRule ^i/t/([^/]+)/.+?\.jpg$ /i/404/$1.jpg [L,NC]
Also make sure to move this rule as first rule just below RewriteBase / line.

wordpress change to friendly URL with variable using htaccess

I have a wordpress site with a page template and 1 variable call uid (user id) , and I wanna change it to friendly url.
from
http://localhost/forum/edit-profile/?uid=1
to
http://localhost/forum/edit-profile/1
or
http://localhost/forum/edit-profile/uid/1
P/S: wordpress already has a .htaccess file , i just wanna add some additional codes to this.
I tried these solutions, but they are not working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /forumengine/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forumengine/index.php [L]
RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
</IfModule>
Add this to your .htaccess rules
RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
This would redirect /forum/edit-profile/?uid=1 to /forum/edit-profile/1 and back.
EDIT : (with wordpress rules they should go like)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /forumengine/
RewriteRule ^index\.php$ - [L]
RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forumengine/index.php [L]
</IfModule>

Static Url Redirection in Wordpress

I need to redirect page1 to something/page1 in my wordpress site.
i have tried the below rule in my htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^page1/$ something/page1? [L]
</IfModule>
# END WordPress
i am not familiar in htaccess rules. but the redirection is not working.
can any one help me?
Thanks
Maybe this will work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Next line added
RewriteCond %{REQUEST_URI} !page1 [NC]
RewriteRule . /index.php [L]
# Next 3 lines added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page1 something/page1? [L]
</IfModule>
# END WordPress
For permanent and visible redirection, replace [L] with [R=301,L] in the last rewrite rule.

query Redirect issue with wordpress

I am trying to setup a query redirect for my category pages
Currently the url is as follows:
http://chunkydeals.com/daily-deals/?category=alldeals
I am trying to get it to be something like:
http://chunkydeals.com/daily-deals/alldeals/
my htaccess code is as follows:
# 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 %{QUERY_STRING} ^category=([a-z])*)$
RewriteRule ^daily-deals/$ http://chunkydeals.com/daily-deals/%3/? [R=301,L]
</IfModule>
# END WordPress
Any help would be appreciated
Have you tried putting the QUERY_STRING rules above the one that rewrites to index.php? (which prevents the regex ^daily-deals/$ from matching)
RewriteBase /
RewriteCond %{QUERY_STRING} ^category=([a-z])*)$
RewriteRule ^daily-deals/$ http://chunkydeals.com/daily-deals/%1/? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Resources