.htaccess Rewrite issue. Possibly reserved words? - php

This does not require much explanation, quite simply, how does the following work:
RewriteRule ^errors/browser/?$ /_errors/browser.php?error=browser [NC,QSA,L]
and this does not work:
RewriteRule ^error/browser/?$ /_errors/browser.php?error=browser [NC,QSA,L]
The only difference in two above snippets, is the removal of the letter s from the end of the word error
I cannot understand why the addition of an s on the word error suddenly makes this code work. The only explanation I can think of is that error is a reserved word? Is this the case?
If this is the case then how can I match and rewrite the word error using an .htaccess file?
UPDATE
This is my whole .htaccess file:
# Define the default document
DirectoryIndex index.php
# Turn on the rewrite engine
RewriteEngine On
# Compress all HTML, Javascript, CSS, XML... files
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Set the error page rewrites
RewriteRule ^errors/browser/?$ /_errors/browser.php?error=browser [NC,QSA,L]
# Set the general first level rewrites
RewriteRule ^([a-z-]+)\/?$ $1.php? [NC,QSA,L]
RewriteRule ^([a-z-]+)\/([a-z-0-9]+)\/?$ $1.php?id=$2& [NC,QSA,L]

Quite strange that vim will highlight the word "error", but you may simply try this to hack it:
RewriteEngine On
RewriteRule ^erro[r]/index.html [NC,QSA,L]
And here is an issue maybe related: question-10872503

Related

.htaccess Internal Server Error while enabling Gzip

I am trying to enable Gzip compression on my wordpress website. But when i try to add the compression code, i am getting the following error.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#coachhire4u.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.18 (Unix) OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 PHP/5.5.31 Server at www.coachhire4u.com Port 80
My .htaccess file,
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/customer/quote/payment/
RewriteRule (\d+)/(\d+) http://www.coachhire4u.com/?c4u_payment_id=$1
[L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Compression code
# Compress HTML File, CSS File, JavaScript File, Text File, XML File and Fonts
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
Please help me to resolve this issue. I know there are similar posts, but none of them seem to help
thanks
There are different approchaes of achieving compression. Which one to use depends on the capabilities/setup of your server. It's always a good idea to surround blocks with <ifModule></ifModule> where possible, in order to prevent 500 status errors.
There's a good chance that the following will work on your local machine as well as on your server. However, with the sparse informatione provided, it's not possible to give a definite answer. But I'll gladly update this answer if this does not work and you can provide further debugging information.
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|json|php|pl|svg)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^application/json.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
AddOutputFilterByType DEFLATE font/truetype font/opentype
</ifModule>
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
It might be a bit late, but I hope this helps.
I fixed my error by going to httpd.conf for my Apache server configuration and uncommenting the lines containing mod_filter.so and mod_deflate.so.

/wp-admin/admin-ajax.php 403 (Forbidden)

I'm running WordPress on Windows server 2012 R2 in an Azure VM. In one of my sites, the theme options panel is not updating. When I check the console, I see that this error: /wp-admin/admin-ajax.php 403 (Forbidden).
The .htaccess file in the root folder looks like 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]
# Forbidding PHP files execution
<FilesMatch “\.(php|php\.)$”>
Order Allow,Deny
Deny from all
</FilesMatch>
# END WordPress
#GZIP Compression
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
I've tried adding another .htaccess file into the wp-admin folder with the following:
<IfModule mod_security.c>
SecFilterEngine Off
</IfModule>
But this does not work.
My permissions for the files are set like this:
https://www.customfitonline.com/news/2013/6/20/solve-wordpress-on-windows-server-problems/
Any ideas on how to get this working???

Site doesn't work on localhost with the ".htaccess"

I neet to put a CMS that i got, to work on localhost, the problem is that it is working only if i delete the .htaccess file. If the .htaccess is in the root folder the site doesn't work and when i delete the .htaccess file and the site is working i can't access the admin pannel using "http://localhost/putina/admin", I receive the error "The requested URL /putina/admin was not found on this server.". Here is my .htaccess:
Options -Indexes
RewriteEngine On
#RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>

RewriteRule redirecting to index.php

This is something weird.
In a website that I'm working on, which uses Zend framework, there was a requirement to redirect any URLs ending with "/" (e.g., http://test.com/test-url/) to the same URL without the "/" (e.g., http://test.com/test-url).
I added this to the .htaccess file:
RewriteRule ^(.+[^/])/$ /$1 [R=301,L]
For many URLs this is working fine. But for URLs like http://test.com/index/test-url/ this gets redirected to http://test.com/index.php/test-url, which is undesired. Can somebody throw some light on why this happens please?
I know you can complain about the unfriendly URLs like "/index/test", but I need to live with it for now :)
The requirement was to avoid these being seen as duplicate URLs by search bots, which affects SEO as some believe.
Here is the complete .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^(.+[^/])/$ /$1 [R=301,L]
# Some other strange redirections
RewriteRule ^index/$ / [R=301]
RewriteRule ^css/$ / [R=301]
RewriteRule ^js/$ / [R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
# compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
</IfModule>
This behaviour seems to surface when you have the MultiViews option turned on. Multiviews allows for content negotiation with mod_negotiation. You can turn it off by adding the following in the very top of your .htaccess:
Options -MultiViews
For more information, see the documentation and some more information about content negotiation.
Alternatively you can rename index.php to prettybutterflies.php and change your RewriteRule to:
RewriteRule ^ prettybutterflies.php [NC,L]

htaccess redirects to another port and appends keyword to my uri

Im on ubuntu and I have varnish cache, I searched my problem a lot but could not find it,
when I enter
http://127.0.0.1/soccer
This uri means require soccer.php, My browser redirects me to,
http://127.0.0.1:8000/soccer/?tab_id=soccer
But when I type,
http://127.0.0.1/soccer/
this one works okay and interesting thing is, this problem only happens in "soccer" and "save" keywords,
this is my .htaccess
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.php>
SetOutputFilter DEFLATE
</files>
<files *.html>
SetOutputFilter DEFLATE
</files>
RewriteEngine On
Options -MultiViews
RewriteRule ^([//0-9a-zçöşığüA-ZÇÖŞİĞÜ-]+)$ tab.php?tab_id=$1 [QSA,L]
What's happening here is probably mod_dir interferring with the processing of your URI. By default, if mod_dir is loaded, it'll add a trailing slash to the end of a URI that it thinks maps to a directory when the trailing slash is missing. This causes issues when the URL/File mapping pipeline causes what looks like a directory to be processed by a file (e.g. via mod_rewrite), mod_dir doesn't know because this happens further down the pipeline, thus mod_dir marks the URI to be a redirect, then other things happen to it further down (or up) in the pipeline, finally resulting in a URI that got processed by multiple modules that got redirected when the redirect shouldn't have happened.
To clarify, when I mean "it'll add a trailing slash to the end of a URI", I mean that mod_dir 302 redirects the browser to the same URI except it ends with a trailing slash.
You can try a couple of things:
Turn off mod_dir by including a DirectorySlash Off. This makes it so mod_dir won't redirect the browser, but note that there are other consequences to turning this off. You can add that directive in your htaccess file.
Handle the trailing slash in mod_rewrite:
RewriteEngine On
Options -MultiViews
RewriteRule ^([//0-9a-zçöşığüA-ZÇÖŞİĞÜ-]+)$ /$1/ [L,R=301]
RewriteRule ^([//0-9a-zçöşığüA-ZÇÖŞİĞÜ-]+)/$ tab.php?tab_id=$1 [QSA,L]

Categories