Expression Engine - htaccess to hide index.php is not working. Why? - expressionengine

I have an MSM install with four (licensed) sites. Three of them work perfectly and behave as they should. The fourth one, currently under construction seems to have a mind of its own. The home page shows up but attempts to add additional templates or template groups with content do not display. I only get
The requested URL /template-name/ was not found on this server.
I double checked and made sure the Enable Strict URLs was set to No and the templates are all synched properly. At this point I am repeating myself. Any clues?
Edited
I found out that if I insert index.php into the URL the other pages and templates will show, which leads me to believe that I have something wrong with the htacess file.
Here is the code I am using (which has worked just fine for other sites):
# BEGIN ExpressionEngine Rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php?$1 [L]
</IfModule>
# END ExpressionEngine Rewrite
Any clues why this is not working correctly?

Turns out it was the htaccess file. I replaced the rewrite noted above with the following and it solved the problem:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

Related

Rewrite URL with just company name with current htaccess file

First I like to say I feel so privileged being here. I have used the answer given here for many years and it has saved me many many hours. I have searched for the answer to my current question with no luck. I believe the answers didn't work because I am adding it to my current .htaccess file which is required. I have asked in my current software program (phpfox) forum but they said it could not be done. I will leave it to stackoverflow experts to tell me whether it can be done or not. Here is my current .htaccess file
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(file)/(.*) PF.Base/$1/$2
RewriteRule ^static/ajax.php index.php
RewriteRule ^themes/default/(.*) PF.Base/theme/default/$1
RewriteRule ^(static|theme|module)/(.*) PF.Base/$1/$2
RewriteRule ^(Apps|themes)/(.*) PF.Site/$1/$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
Here are three examples of the URL for this business page.
DomainName/directory/detail/302/name-of-business/overview/
DomainName/directory/detail/302/name-of-business/aboutus/
DomainName/directory/detail/302/name-of-business/contactus/
I think you get the picture but just in case here is a different business.
DomainName/directory/detail/303/name-of-business/overview/
Now for this business page the /directory/details never changes. The 302 is the primary id of the record in the database table for this business. In that same record is the name-of-business. So if I type in the browser URL DomainName/directory/detail/302 it will still bring me to main overview page even without "name-of-business/overview" at the end of the URL. So I am assuming the php code throws that at the end of the url from the database depending on what menu you click on this specific business.
My dream hope is getting it down to
DomainName/name-of-business/overview
DomainName/name-of-business/contact etc...
But I would even be happy to get rid of at least directory/detail (I am guessing the id "302" is needed since it is the main identifier...just guessing).
DomainName/302/name-of-business/overview
I have tried many different answers here but I feel I also may be putting it on the wrong line in my current .htaccess file. Thank you in advance for any help and your time.
Try with:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(file)/(.*) PF.Base/$1/$2
RewriteRule ^static/ajax.php index.php
RewriteRule ^themes/default/(.*) PF.Base/theme/default/$1
RewriteRule ^(static|theme|module)/(.*) PF.Base/$1/$2
RewriteRule ^(Apps|themes)/(.*) PF.Site/$1/$2
# Rewrite DomainName/303/... to DomainName/directory/detail/303/...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d+)(/.*|$) index.php?q=directory/detail/$1$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
Rewrite DomainName/303/... to DomainName/directory/detail/303/...
but only for external links or once fixed in your pages

Remove index.php from url for ONLY CI subdirectory

I get how to remove index.php from CI urls overall. The following works fine:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /crm/v2/index.php?/$1 [L]
However, it interfers with other code on the live site. This new CI version i'm adding is in a subdir named v2. Thus the layout is something like:
-originalDir
--v2
-otherDirs
-.htaccess
-etc...
So in essence urls come out something like:
// Original page
https://www.site.com/originalDir/somepage.htm
// And this exist too
https://www.site.com/originalDir/index.php
// My new stuff
https://www.site.com/originalDir/v2/index.php/controller/etc...
// Desired effect withOUT affecting the original sites index.php page
// aka, the below is what i WANT but NOT getting!
https://www.site.com/originalDir/v2/controller/etc...
I can code in a lot of languages, but never a lot of experience with these htaccess rewrites. Any ideas on how to make it rewrite index.php for ONLY the codeigniter sub-directory? I've tried a few things that seem to work locally, but not on the live server. Not sure the exact structure of rewrite code.
Assuming you want to only rewrite rules in the CI directory, and not point any URLs outside of that directory to it...
Change your RewriteRule to match only URI's that start with your CI directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^crm/v2/(.*)$ /crm/v2/index.php?/$1 [L]
Alternatively, you can put an .htaccess file in your /crm/v2 directory, and specify a RewriteBase.
RewriteEngine on
RewriteBase /crm/v2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Have you tried using RewriteBase?
RewriteEngine On
RewriteBase /crm/v2
RewriteRule ^(.+)$ index.php?/$1 [L]
I have not tested this specifically with your information but this is from a template that I use for some of my projects.
Here is the documentation for RewriteBase: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
I hope this helps!

Limit RewriteRule in htaccess file

i got a site php based with some rules in the .htaccess file to get rid of file extentions in the url adress bar. Basically it takes http://netbureau.com.br/en/about.php/ and turns it into http://netbureau.com.br/en/about.
Here are the lines in the htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The problem comes when i try to access the rss feed of the blog at http://netbureau.com.br/blog/?feed=rss2 and when i try to set custom permalinks for the blog at http://netbureau.com.br/blog. It gets messed up by the htaccess file.
So is there any way to disallow the RewriteRule for the /blog folder so that i can get back my rss link and set custom permalinks in the blog?
I know it's at the same time Wordpress related but it feels more connected to the htaccess file than Wp.
Thanks in advance.
EDIT #1:
I've set up the wordpress permalinks to the default structure which goes like this: http://netbureau.com.br/blog/?p=123 This made my rss link back for good.
The remaining problem is that Wordpress gives me its own rewriterule which is:
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
Is there a way to to still use the first rule to apply to the whole site except the /blo/ folder and apply the WP rule only to the /blog/ folder?
I've tried different combinations but without luck so far. I could only have the site without the custom links for the blog or the custom blog links and a 404 on the pages of the site.
Try:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/blog/?
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The !^/blog/? expression excludes any URI that starts with /blog

using - instead of _ (underscore) with .htaccess

I'm using with good results the following code to access alla of my php files into the /it directory without specifying the extension. In other words I can access to "http://www.mydomain.com/it/about.php" just writing "http://www.mydomain.com/it/about".
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.mydomain.com/it/$1.php [L]
the same happen when i try to access to http://www.mydomain.com/it/question_answers.php.
How can I access directly to *"http://www.mydomain.com/it/question_answers.php"* also writing "http://www.mydomain.com/it/question-answers"?
I wrote the floowing code below the previous but it seems not to work.
Redirect 301 /question-answer http://www.mydomain.com/it/question_answer.php
because if i write "http://www.mydomain.com/it/question-answer" the browser try to open the page:
"http://www.mydomain.com/it/question-answer.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php"
A small abstract of the post:
I have the page *"http://www.mydomain.com/it/question_answers.php"*
with the first part of code I can get it using the link *"http://www.mydomain.com/it/question_answers"*
I'd like to access the same page also with the following "http://www.mydomain.com/it/question-answers"
Thanks!
This should work for you:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.mydomain.com/$1.php
RewriteRule it/question-answer\.php http://www.mydomain.com/it/question_answer.php [R=301,L]
I have changed two things: I deleted it/ in the new URL of the first RewriteRule. Otherwise you would be redirected to it/it/
I also added \.php to the second RewriteRule. I don't really know why, but the RewriteRule seems to replace the pattern instead of redirecting. And if your pattern is it/question-answer and the real url is it/questions-answer.php the .php will not be replaced.

Apache2 Mod rewrite page not found

I'm sorry that I'm not exactly sure how to phrase the question in a single sentence.
Basically, mod rewrite is working for our traq pages (code block 1 below), but not for our wordpress pages (code block 2 below). For some reason, if we implement the automatically generated Wordpress .htaccess file, the page comes up with Apache's "page not found" error (which means that it's never hitting Wordpress's index page at all).
Traq:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
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>
We tried commenting out a few of the various lines in the Wordpress file, and altering various lines as we thought one thing or another might have been causing the issue. In the end, none of our changes got anything to display except 404.
We found the issue.
Our server is set up pretty much as Ubuntu from distro, and by default the apache package is configured to allow overwrite with htaccess / mod-rewrite, but not to allow any rewrite rules. We had to add the rules we wanted to allow to the apache config.

Resources