I have an MT site with the standard ExpressionEngine htaccess code to remove index.php and the home page works, and all other pages work if I put index.php in the URL. Without it, I get "no output file specified". It works on my local and non-MT server, so I know its an environment thing. What in the htaccess needs to be changed to make it work on MT?
<IfModule mod_rewrite.c>
# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /
# Use Dynamic robots.txt file
# ------------------------------
RewriteRule robots\.txt /robots.php [L]
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/admin/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
Thanks to #danielcgold for the answer via twitter:
Try using this line RewriteRule ^(.*)$ /index.php?/$1 [L] and note the ? after index.php
I posted a Gist last night with my standard rewrite rules for all my ExpressionEngine sites on (mt).
## BEGIN Expression Engine Rewrite
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
## END Expression Engine Rewrite
Using EE 2.7.0 and Mediatemple's Grid service (formerly "GS"), I've had luck using the standard .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
but then going into the AccountCenter > [mydomain.com] > PHP Settings, and changing the PHP version from 5.5.1 CGI (latest) to 5.3.7 CGI (stable).
I posted this solution on the ExpressionEngine Stack Exchange site, but in a nutshell the shared hosting environment we had to use was forced to use FastCGI, and we couldn't modify any CGI or PHP configurations.
In an attempt to create the $_SERVER['PATH_INFO'] variable myself, what worked for me was this 3 step 'custom' approach:
First, in ExpressionEngine > CP Home > Admin > System Administration > Output And Debugging, I set Force URL query strings to No.
Next, as mentioned in previous answers, I changed the .htaccess directive from RewriteRule ^(.*)$ /index.php/$1 [L,QSA] to RewriteRule ^(.*)$ /index.php?/$1 [L,QSA] (extra ? after index.php).
Finally, I added this piece of custom PHP code to the top of site root's index.php file to "force" the $_SERVER['PATH_INFO'] variable into accurate existence:
<?php
$path = $_SERVER['REQUEST_URI'];
$pos = strpos($path, '?');
if ($pos !== false)
$path = substr($path, 0, $pos);
$_SERVER['PATH_INFO'] = $path;
/**
* ExpressionEngine - by EllisLab
...
...
I hope this helps someone! I really pulled my hair out trying to find somewhat more elegant solutions!
Related
I have installed Yii2 advanced app and what i am trying to do now is to redirect this url htpp://site/admin to the backend ( admin ) side. What i tried so far is:
AddDefaultCharset utf-8
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# Make the backend accessible via url: http://site/admin
RewriteRule ^admin$ $admin.php [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule ^static - [L]
I am not familiar whit .htaccess and i am not pretty sure what is the right way. This code is what i found after googling. The .htaccess file is in the app/backend/web/.htaccess. Can you point me the right way? Thank you in advance!
easy :
RewriteEngine On
# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend)/web/ - [L]
# Handle the case of backend, skip ([S=1]) the following rule, if current matched
RewriteRule ^admin(/(.*))?$ backend/web/$2 [S=1]
# handle the case of frontend
RewriteRule .* frontend/web/$0
# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php
I have my htaccess file setup, so that the pages remove extensions. Now, I am trying to make the pages that transfer variables, into SEO friendly urls ... so, for example...
http://www.example.com/art-gallery?page=2 ... which is actually "art-gallery.php?page=2", would turn into... http://www.example.com/art-gallery/page/2
Or... http://www.example.com/art-piece?id=3 ...would go to... http://www.example.com/art-piece/id/3
... and so on ...
I have alot in my htaccess file, and am not sure how to do the above (there are plenty of tutorials on going from www.example.com/index.php?page=2 to www.example.com/page/2/ but none that do exactly what I need). Ideally, I'd like to be able to do this for all similar pages...
# enable the rewrite engine
RewriteEngine On
# Set your root directory
RewriteBase /
# Force www:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
# Remove the .php extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# Remove index and reference the directory
RewriteRule (.*)/index$ $1/ [R=301]
# Remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# Forward request to html file, **but don't redirect (bot friendly)**
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
# Disable Directory Browsing
Options -Indexes
# Disable Hotlinking of Images
# with forbidden or custom image option
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]
# Protect htaccess File
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>
You can transfer parameters with the variable QUERY_STRING.
Consider the following rule:
RewriteRule ^index.html index.php?%{QUERY_STRING}&m=main&a=index
This rule would transform
index.html?something=value
into
index.php?something=value&m=main&a=index
You should use the RewriteEngine.
You could also use a 301 redirect either alone or in conjunction with the RewriteEngine to redirect SEs.
Generally, though redirecting SEs to a different page than what users will see is not a good practice, and may result in your pagerank decreasing. Instead, try migrating all your pages to the second URL format, and consider using 301 redirects to help the transition.
Generally: Use 301 redirects for SE-friendly page changes. See this SO for additional reference.
You can insert this rule just before Forward request to html file rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/])/([^/])/([^/])/?$ $1.php?$2=$3 [L,QSA]
This is quite old but why not do the following:
RewriteEngine On
RewriteRule ^([^?]*) index.php?route=$1 [L,QSA]
Then in your index.php you can handle it like such;
if (isset($_GET['route'])) {
$route = explode('/', $_GET['route']);
if (iconv_strlen((end($parts)), 'UTF-8') == 0) {
array_pop($parts);
}
}
From here your main level would be handled with $route[0], second level $route[1]
For example;
http://example.com/art-gallery/2
$route[0] would equal 'art-gallery'
$route[1] would equal '2'
I've got a problem trying to install Social Engine. Upload all files, set directory permissions, but when I enter my domain, I get a:
Not Found
The requested URL /install/install was not found on this server.
It's something related to the .htaccess files in root and install directory, 'cause removing them I do begin the installation process BUT with long URLs, this way:
/install/index.php/install
And that's something that would end up with all long URLS, instead of short ones that google use to index, for example. My ISP has safe_mode OFF, and mod_rewrite ON, so I'm just kinda lost...
.htaccess :
# $Id: .htaccess 7539 2010-10-04 04:41:38Z john $
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On
# #todo This may not be effective in some cases
FileETag Size
Had the same issue running SocialEngine on Vagrant (using https://box.scotch.io/) and fixed it by clearing the .htaccess file under /install/.
I'm having trouble with some URL rewriting.
All of the stuff below works fine, but I need to add a rule which removes querystrings from URLS.
site.com/page?a=b
will become
site.com/page
Can someone help out? I have done some reading on .htaccess but I find it terribly complex. Also, will need to know where in the file my new directives should appear.
Thanks.
# EE 404 page for missing pages
ErrorDocument 404 /index.php/404/index
# Simple 404 for missing files
ErrorDocument 404 "File Not Found"
# Rewriting will likely already be on, uncomment if it isnt
RewriteEngine On
RewriteBase /
# Block access to "hidden" directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or Git.
RewriteRule "(^|/)\." - [F]
# remove the www - Uncomment to activate
#
# RewriteCond %{HTTPS} !=on
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#
# Remove the trailing slash to paths without an extension
# Uncomment to activate
#
# RewriteRule ^(.*)/$ /$1 [R=301,L]
#
# Remove index.php
# Uses the "include method"
# http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method
#
RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC]
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(home|inc|publishers|sidebars|about|include-template|testing|advertisers|products|sitemap|style|ad-choices|social-bar|search|404||members|P[0-9]{2,8}) [NC]
RewriteRule (.*) /index.php/$1 [L]
This would remove query string from url
RewriteRule ^(.*) /index.php/$1? [L] #remove query string
Hope it helps
I'm a little late for an answer, but since i was searching for a similar behaviour, i thought i should share it: you can also add a flag to a rewrite rule to remove the query string; the flag is [QSD], and it helps avoiding workarounds like the ? at the end ;-)
Here you can find more about this flag. I feel like pointing out that "This flag is available in [Apache] version 2.4.0 and later"
I use the cms expressionegine. I want to shorten my url
from
http://sionvalais.com/live/sionvalais
to
http://sionvalais.com/sionvalais
'sionvalais' is the weblog name in EE
live is the subdirectory in which EE is installed. Would someone be so kind as to help me with this?
RewriteEngine on
RewriteBase /
# rewrites http://sionvalais.com/sionvalais/* to expression engine
# respectively http://sionvalais.com/live/sionvalais/index.php*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond $1 !\/live*
RewriteRule ^sionvalais/?(.*)$ live/sionvalais/index.php?$1 [L]
# rewrites http://sionvalais.com/live/sionvalais* to http://sionvalais.com/sionvalais*
# and sets http status code 301, so search engines 'forget' about your live directory
RewriteCond $1 !\/index\.php*
RewriteRule ^live/sionvalais(.*)$ /sionvalais$1 [L,R=301]
Here's something to try in your .htaccess file:
RewriteEngine on
RewriteCond $1 !^live
RewriteRule ^sionvalais(.*)$ live/sionvalais$1
It may need more refinement, but it seems to work in a very basic sandbox.