I need to translate some htaccess rules for the nginx server,
my htaccess was:
RewriteEngine On
RewriteBase /mysite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
SetOutputFilter DEFLATE
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>
i've translated this part
RewriteEngine On
RewriteBase /mysite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
that looks like
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/(.*)$ /mysite/index.php/$1 last;
}
is it ok?
Then I need to translate the second part of the htaccess (showed above).
How can I translate that?
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/(.*)$ /bitfungus/index.php/$1 last;
}
is it ok?`
No, it's ugly. Nginx isn't apache, you should not use rewrites where you don't actually need them (in about 95% cases you don't need rewrites in nginx).
http://wiki.nginx.org/Pitfalls
Correct:
try_files $uri $uri/ /bitfungus/index.php$uri;
Related
I have this .htaccess file for my Vue.js project which allows my Vue.js to use the history routing mode. Unfortunately, the .htacess doesn't take effect when I put it in my Vue.js project folder that is located on my DigitalOcean Ubuntu droplet. I know there's nothing wrong with the .htacess file because it does what it is supposed to do on my personal PC.
Is there some sort of Apache setting I need to turn on first, which I'm forgetting about? The file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/webp A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/css A86400
ExpiresByType text/javascript A86400
ExpiresByType application/x-shockwave-flash A2592000
#
<FilesMatch "\.(gif¦jpe?g¦png¦ico¦css¦js¦swf)$">
Header set Cache-Control "public"
</FilesMatch>
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
How can I do a rewrite rule for both http://domain/abc to rewite/redirect to http://domain/abc.html but it should work when I have url as http://domain/abc/def.html. Currently when I do redirect 301 "abc" "abc.hml" the second url is also redirecting to http://domain/abc.html/def.html.
My current rules.
<IfModule rewrite_module>
RewriteEngine On
RewriteRule ^/$ /content/aaa-123/abc.html [PT,L]
RewriteRule ^/index.html$ /content/aaa-123/abc.html [PT,L]
RedirectMatch ^/abc$ /abc.html
RewriteCond %{REQUEST_URI} !^/(.*)/$
RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$
RewriteRule ^/(.*)$ /content/$1/ [L]
RewriteRule \.(css|jpe?g|gif|png|js)$ - [L]
ErrorDocument 404 /errors/404.html
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
Thanks
Use RedirectMatch instead of Redirect to match using regular expressions:
Options -MultiViews
RewriteEngine On
RewriteRule ^/abc/?$ /abc.html [NC,L,R=302]
RewriteRule \.(css|jpe?g|gif|png|js)$ - [L,NC]
RewriteRule ^/(index\.html)?$ /content/aaa-123/abc.html [PT,L,NC]
RewriteCond %{REQUEST_URI} !^/(.*)/$
RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$
RewriteRule ^/(.*)$ /content/$1/ [L]
Clear your browser cache before testing this rule and do restart Apache after making these changes.
For the first you could use this:
RedirectMatch ^/abc$ /abc.html
This tells apache to redirect only "/abc"
Although it sounds as you want MULTIVIEWS in Apache. Multiviews is an Option with which Apache will examine a request and add an extension if it finds a file matching the request, so if you request abc and there is abc.html it will load it.
I have Laravel application that is using mod_expires, mod_headers, and mod_gzip in the public folder to enable caching on the frontend of the site. However, in the admin panel this is breaking some of the functionality.
I would like to disable/exclude the paths to the admin panel which are generated using mod_rewrite. I would have just put a .htaccess file in a folder with the same name as path, but this causes issues as well.
The path to the admin panel would be "/manage".
Here's what the .htaccess file looks like at this time.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Secure Front Themes...
RewriteRule ^themes/.*\.(blade.php|php)$ - [F,L,NC]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2692000, public"
</FilesMatch>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=2692000, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</FilesMatch>
<FilesMatch "\\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</FilesMatch>
Header unset ETag
Header unset Last-Modified
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
Thanks in advance
In a nutshell the script im using is not working
the script
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profiles.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profiles.php?key=$1
the original url :
http://localhost/profiles?profile_key=yasin%20allana
the desired url:http://localhost/profiles/yasin%20allana
the error:The server encountered an internal error or misconfiguration and was unable to complete your request.
how do i correct the errors
note:the server is v 1.8.3 xampp
the complete htaccess script
<IfModule mod_deflate.c>
<FilesMatch "\.(html|txt|css|js|php|pl)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# BEGIN Expires
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>
# END Expires
#override the limit on upload in php
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_input_time 300
php_value max_execution_time 300
You can use this rule in /profiles/.htaccess file:
RewriteEngine On
RewriteBase /profiles/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/?$ profiles.php?key=$1 [L,QSA]
i have my site where in pas i have a article directory but now i have deleted that article directory and google webmaster is shoing those links as not found and its a negative impact on my search results.
pls help me to redirect all links like this
http://www.mydomain.com/article/arts-entertainment/bradley-spalter-songs-getting-past-emotionally-charged-barriers/
to
http://www.mydomain.com
Current .htaccess file:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 day"
ExpiresByType text/plain "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/javascript "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 15 days"
</IfModule>
## EXPIRES CACHING ##
Options -MultiViews -Indexes +FollowSymlinks
RewriteCond %{http_host} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]
RewriteRule ^golmagico/(.*)$ en/index.php?title=$1 [PT,L,QSA]
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
ErrorDocument 401 /default_error.php
ErrorDocument 402 /default_error.php
ErrorDocument 403 /default_error.php
ErrorDocument 404 /default_error.php
<IfModule mod_php5.c>
php_value register_globals 0
php_value magic_quotes_gpc 0
php_value session.auto_start 0
php_value safe_mode 0
</IfModule>
<IfModule sapi_apache2.c>
php_value register_globals 0
php_value magic_quotes_gpc 0
php_value session.auto_start 0
php_value safe_mode 0
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^detailed/recent/?([^/\.]+)?/?$ video.php?category=recent&page=$1&viewtype=detailed
RewriteRule ^detailed/viewed/?([^/\.]+)?/?$ video.php?category=viewed&page=$1&viewtype=detailed
RewriteRule ^detailed/recentviewed/?([^/\.]+)?/?$ video.php?category=recentviewed&page=$1&viewtype=detailed
RewriteRule ^detailed/discussed/?([^/\.]+)?/?$ video.php?category=discussed&page=$1&viewtype=detailed
RewriteRule ^detailed/favorites/?([^/\.]+)?/?$ video.php?category=favorites&page=$1&viewtype=detailed
RewriteRule ^detailed/rated/?([^/\.]+)?/?$ video.php?category=rated&page=$1&viewtype=detailed
RewriteRule ^detailed/featured/?([^/\.]+)?/?$ video.php?category=featured&page=$1&viewtype=detailed
RewriteRule ^detailed/random/?([^/\.]+)?/?$ video.php?category=random&page=$1&viewtype=detailed
RewriteRule ^recentviewed/?([^/\.]+)?/?$ video.php?category=recentviewed&page=$1
RewriteRule ^videos/?([^/\.]+)?/?$ video.php?category=recent&page=$1
RewriteRule ^recent/?([^/\.]+)?/?$ video.php?category=recent&page=$1
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
</IfModule>
Try putting this in your .htaccess
ErrorDocument 404 http://www.mydomain.com
it'll redirect all 404's to your domain.
or you can try:
RewriteRule ^articles/.*?$ / [NC]
to redirect all requests to the articles folder to root
Enable mod_rewrite
Enable .htacccess
Create a .htaccess file under DOCUMENT_ROOT
and place this code in there:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^article/ / [NC,L,R=301]
R=301 will tell Google and other search bots that all the links starting with /article/ have permanently moved to / (home page) and you will not have any negative impact on your rankings.