Override Wordpress Url Rewriting - wordpress

I'm trying to override wordpress url rewriting for 1 specific file. My current wordpress install rewrites .html files to the according .php extension. So, for a permalink in MY wordpress installation might look like www.mysite.com/mypage.html.
I have an ACTUAL HTML file i want to show, however the htaccess keeps auto rewriting it by default, here is the code i'm trying to use to IGNORE this specific file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/forex-system-demo\.html$ [NC] #<-- This is the file i want to ignore and run as a NORMAL .HTML file
RewriteRule . /index.php [L]
</IfModule>
I may have had some wierd browser caching going on because what is below now works after clearing cache.
Here is the SOLUTION:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^forex-system-demo.html$ - [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Here is the SOLUTION:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^forex-system-demo.html$ - [L] # <- this is where I tell wordpress to ignore this url
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Related

Redirect HTTPS to HTTP for a single file in Wordpress

I need to let an external software collect a zip file from my Wordpress site. The site is converted to https, but the software asks for the HTTP version of the file, http://www.example.com/foldername/grunfil.zip
So can I add something in .htaccess to make that file only http?
Here is my current .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 tried this, but it creates an endless loop:
redirect 301 /foldername/grunfil.zip http://www.example.com/foldername/grunfil.zip
Check this rule, maybe it help.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^foldername\/grunfil\.zip
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

.htaccess and regular expression remove part of the uri

I would like to redirect path like this
http://www.example.com/uploads/2017/10/image.ext/version/?id=87988984632
to
http://www.example.com/uploads/2017/10/image.ext
where extension could be whatever image or video extension.
I'm can detect the last part with this \/version\/(.*)$ but I can't remove from the uri.
Update:
This is my .htaccess and I'm using 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]
RewriteRule \/version\/(.*)$
</IfModule>
Thanks for your help
You can use this new redirect before other WP rules:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/version/?$ /$1? [L,NC,NE,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

index.php added in url with virtualhost on wordpress

I created a virtualhost with MAMP. It works well when I go to example.dev. I just installed a wordpress on example.dev without any problems. When I display a page or a post, there is a /index.php which is added before the page name. For example : example.dev/index.php/pagename.
I can not access example.dev/pagename, i have a 404 error.
In permalink's options, it generates automatically /index.php/%year%/%monthnum%/%day%/%postname%/.
I selected http://example.dev/example-article/ but it is still not working.
I have a htaccess at the root
RewriteEngine On
# 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
If somebody has an idea...
Thank you !!
To this url /index.php/%year%/%monthnum%/%day%/%postname%/ will work on Apache server add this rule to .htaccess file
RewriteRule ^index.php/(.*)/?$ /$1/ [L]
Above the WordPress rules:
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Given that your .htaccess have the basic WordPress rules it would look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php/(.*)/?$ /$1/ [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
END WordPress

wordpress htaccess doesnt change url, just goes to 404

The line of code:
RewriteRule ^/test/(.*)/?$ http://test.com/test/index.php?route=$1 [L,QSA]
has no effect in the htaccess file that I am using:
# 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]
RewriteRule ^/test/(.*)/?$ http://test.com/test/index.php?route=$1 [L,QSA]
</IfModule>
# END WordPress
When I visit my domain.com/test/123, Wordpress redirects be to a 404 page not the new link.
I have tried moving the items in the htaccess file around in case they are being overwritten, but not luck. any ideas?
Problem 1: RewriteRule doesn't match leading slash.
Problem 2: Wrong order of Rewrite Rules.
Here is the fixed version:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*)/?$ http://test.com/test/index.php?route=$1 [L,QSA,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Exclude a folder/directory from RewriteRule

I have a pretty standard WordPress .htaccess with the following URL rewrites
# 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
WordPress is installed in my domain root. I have some other scripts in subfolders, e.g. /opencart These subfolders contain their own .htaccess files.
Unfortunately, it seems that WordPress hijacks the rewrites for some of these scripts sometimes.
How can I ask mod_rewrite to ignore WordPress rules for rewrites when encountered with specific subfolders e.g. opencart and to use the rules defined in the .htaccess within these subfolders instead?
You may try replacing the complete WP rule-set with this one:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(folder1|folder2|folder3) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
In the .htaccess file in your site root, add the following ABOVE the WordPress .htaccess directives:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^/(folder1)/(.*) /folder1/$2 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,R]
</IfModule>
# END WordPress

Resources