I have been using .htaccess rules to hide the index page of EE sites for years now and this generally allows me to create a template within the site template group that will display without having to include the name of the site template group in the URL. Like this:
http://mysite.com/template_name
However, I am working on a site where I tried this and I keep getting a 404 error.
Here is the .htaccess code I am using:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Here is the actual path: http://corecubed.com/main/landing-page
This is what it should be displaying as: http://corecubed.com/landing-page
(Note: this page is for mobile devices and displays quite large on a regular web page.)
Question is, why won't it display properly without including the name of the site template group and how do I fix it?
Thanks.
It sounds like Strict URLs are enabled under your Global Template Preferences. Try toggling that setting off.
Related
We have code in our htaccess that presents a different web template for mobile users like
RewriteCond %{HTTP_USER_AGENT} "Mobile"
RewriteCond %{REQUEST_URI} "!_mob.php"
RewriteRule ^(.*).php$ /$1_mob.php [L,QSA]
So a file foo.php would be internally rewritten to foo_mob.php if the condition evaluates to true.
Now we have additional a 'pretty-url' directive that rewrites the descriptive category and product page names to the internal format based on query strings like
RewriteCond %{REQUEST_URI} ^/category1\.htm
RewriteRule ^.*$ /index.php?cPath=1 [L,QSA]
In combination with the above this should then display the template index_mob.php to the user on a mobile device. This has been working fine for many years with Apache server, but is not working anymore after we moved to a LiteSpeed server now. The mobile template is displayed for requests with an explicit .php extension, but not those that have gone through the rewrite to index.php first (that includes also the root / that is rewritten to index.php by default)
Any help to solve the problem would be appreciated.
If you use both above .htaccess rules in Combination while using Litespeed, The problem is the L tag being in the .htaccess twice.
[L] tag stands for Last, and has different meanings in Apache and Litespeed.
The ruleset after an [L] flag may still be processed by Apache on a subsequent iteration, but that is not true with Litespeed and most other contexts.
Additional information and Official Documentation is here.
I'm configuring Expression Engine on Windows using IIS and have ISAPI v3 Rewrite installed.
It's partly working. The main site and subpages work but needs to be modified because some web page assets are stored in similarly named directories.
The recommended Rewrite provided by Ellislabs is this and I've modified it a little to work with our Win 2012 IIS 8 server:
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) abc/$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ abc/index.php?/$1 [L]
For example, the URL http://oursite.example.com/abc works.
Subpages are mostly working and I suspect this applies to any page really but I'm noticing it on subpages. It removes index.php and mostly loads, such as http://oursite.example.com/abc/subdept/page/
However our developer has some assets kept in a server directory named /uploads/abc/ so if a page refers to this directory, it fails to load those assets because it contains the same name, "abc".
Thus, what is the best way to handle this?
I'm guessing I can either tell it to ignore "uploads/cls" or correct the current Rewrite so that it only looks at the first "abc". I'd like for the solution to cover most similar issues that would arise so I don't have to keep modifying it. We have 12 sites and I'll have to apply the solution to each one.
Everything I've tried hasn't worked.
Also, I thought !-f and !-d would tell it to ignore it if the file or directory existed and that doesn't seem to be working as I'd expect here because these images in /uploads/abc/ do exists.
Thanks!
--
Additionally just trying to get it to work at all, I tried adding a htaccess file with "RewriteEngine Off" in the /uploads/abc/ directory and that failed to fix it.
I also tried to add this after each comment and it fails to fix it:
RewriteCond %{REQUEST_URI} !^/excluded-folder/.*$
Seeing how both of the above attempts fail to fix it, I'm wondering if there could be something else going on. Any ideas?
My rewrite was fine. The problem turned out to be code within an Expression Engine template that the in house developer created. They updated the code and the images are loading fine now.
I'm trying to figure out how to manage potentially conflicting conditions in .htaccess
My setup is the following:
- I have a CMS running on a server that can be accessed through myCMSdomain.com where myCMSdomain.com would be CMS home page and myCMSdomain.com/admin would be the admin interface.
- Sites using this CMS should be pointing to myCMSdomain.com/sites/index.php
- Images for all sites are available somewhere behind myCMSdomain.com/admin/images/sitename/...
So here is how I tried to tackle this problem:
RewriteCond %{HTTP_HOST} !^(www.)?myCMSdomain.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sites/index.php
With this, all incoming requests coming from other domain names are treated correctly by the index.php file but as images are hosted somewhere else, I'd like to use a rule saying that images should be fetched somewhere else like this:
Visible url format for images is: images-[sitename]/[image_path]
Real location of the images is: admin/site/[sitename]/[image_path]
The following rule works but not in combination with the first rule
RewriteRule images-([a-zA-Z0-9]+)/(.*)$ admin/site/$1/images/$2
Images end up calling index.php instead of using the rule I defined for them.
I have tried to excluse the image directory from the conditions but it doesn't work either:
RewriteCond %{REQUEST_URI} !(images-([a-zA-Z0-9]+)/(.*))
I might have similar issues in the future with other exception so I was wondering if there was a way to handle this.
Thanks!
Laurent
UPDATE 1:
If I use the following rule on top of all other
it works only if I'm using myCMSdomain.com domain name
if I use any other domain like anotherdomain.com, the rule leads to a http 500
RewriteRule images-([a-zA-Z0-9]+)/(.*)$ manager/site/$1/images/$2
So http://www.myCMSdomain.com/images-test/test.jpg leads me to the correct image
But http://www.anotherdomain.com/images-test/test.jpg leads me to a 500 http error code while this domain is pointing correctly to sites/index.php
UPDATE 2:
On Justin's request, here is a view on the physical directory structure on the server
/admin/
/admin/site
/admin/site/site_name/
/admin/site/site_name/images/
/sites/
/sites/js
/sites/css
You can rearrange your conditions logic.
# if www.myCMSdomain.com or myCMSdomain.com -> do nothing
RewriteCond %{HTTP_HOST} ^(?:www\.)?myCMSdomain\.com$ [NC]
RewriteRule ^ - [L]
# if we reach here, this means it's a subdomain/another domain
# images rule
RewriteRule ^images-([^/]+)/(.+)$ /admin/site/$1/images/$2 [L]
# not a file/directory -> sites/index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /sites/index.php [L]
It is also possible the way you did but it would be longer to write.
Also, keep in mind that conditions (RewriteCond) are non-cumulative: they are for next rule (RewriteRule) only.
I've been struggling with this issue for some time now but at last I think I have found the issue. It looks like there was something wrong in the domain name configuration, I don't know exactly what but once I had re-saved the mapping of all domains, the htaccess worked the way it should.
In the end I have used Justin's proposition, it looks more future proof than mine.
Thanks for your help and happy new year to all
Laurent
I am trying to use the mod_rewrite function to allow my users to create their own unique url's.
Currently, users can access their public profiles by visiting www.mywebsite.com/user/index/4588
where 4588 is that users id number in the database.
I have read up on mod_rewrite here: http://www.branded3.com/blogs/htaccess-mod_rewrite-ultimate-guide/
but I don't know how to test it out.
Someone advised me that the script I am using already uses mod_rewrite to get the users id number for the url, so how can I change it?
Even if to start I could get rid of the /user/index/ part from the url that would be a start.
This is the current .htaccess file in my root which presumably does the current mod_rewrite for public profiles:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Can somebody advise me what to do next in order to start changing it from id's to usernames?
Both are unique within the db.
Looking at your htaccess file seems like you are using one of the php mvc framework (Zend?). If this is a case then you don't need to play with mod_rewrite but configure your framework router.
Have a look at
http://framework.zend.com/manual/1.12/en/zend.controller.router.html
I have a .htaccess file with those contents:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/\.]+)$ index.php?string=$1&match=all [L]
So when I type: domain.com/test
the page redirects to domain.com/index.php?string=test&match=all
But if I want to reach this page: domain.com/test#sub1
the page redirects to domain.com/index.php?string=test&match=all
instead of domain.com/index.php?string=test#sub1&match=all
How do I proceed?
Anchors/hashes are only used by the browser. The server won't see requests for those, because such a request would be invalid. (There is no "test#sub1" file, only a "test" file.) It has no way of knowing you're just wanting to access an anchor and not trying to access a file that doesn't exist, so such information is not passed to the web server.
EDIT: Also, redirecting everything through a single php file just seems like malpractice to me. Maybe there's something special going on here that makes it a reputable approach though.