Apache 1.x vs 2.x .htaccess mod_rewrite - .htaccess

I have a .htaccess on two servers. One is running Apache on CentOS, and one is running Apache2 on Ubuntu. The .htaccess file is there for the purposes of clean urls. Other than js and css files, everything should be re-directed to the /subdirectory/index.php file.
The /subdirectory/.htaccess file is:
RewriteCond %{REQUEST_URI} !(\.css|\.js)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)$ /subdirectory/index.php [L]
On the CentOS server, the redirect appears to work (and removing it, stops the clean urls from working)
http://example.com/subdirectory/widget/add
gets redirected to
http://example.com/subdirectory/index.php
as required, and everything works fine. But on the Apache2/Ubuntu box, no such luck.
Is it there something missing from the .htaccess file for Apache2, or is that it's only working by fluke on the CentOS box in the first place. I'm 2 hours into this and it's driving me nuts.

Related

seturlstrategy- page reload not working :Flutter web 2.0

I have used setUrlStrategy(PathUrlStrategy()); to remove # from the url, but since then my pages stopped reloading after I deploy my project on web, it shows 404 page not found. but works perfectly on localhost.
if I remove setUrlStrategy(PathUrlStrategy()); and build again to deploy on web it works. but that # shows on url.
Can anyone help?
p.s: I used my project on non root location, and have already added my project name in index file, my project works if I open first page to next file, but not directly when open next file from url.
ok i found the problem, it was because i didn't use .htaccess file.
here is htaccess code if anyone get same problem.
RewriteEngine On
RewriteBase /myproject/
RewriteRule ^index\.html$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myproject/index.html [L]
</IfModule>
put this file where your index file is.

content of htaccess slows down Joomla Website

I am trying to remove "index.php" from the url of my website. However it worked with my secondary website but not with my primary.
After renaming htaccess.txt to .htaccess i entered following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
After activating URL-Rewrite in the Joomla-Backend the "index.php" is gone but the sites takes about 20 seconds to load. Clearing the .htaccess makes the site load properly again (about 1 second) but the "index.php" is obviously there again.
It is really important for me to change the URL and maybe someone can help me out :)
Which version of Joomla you are using. If it is 3.x series then there is no need to write your customized code for URL rewriting since it is already present in htaccess. please check for the duplication of code or try to replace with original Joomla htaccess.

Rewrite rule behaving differently between environments

I have two environments, both using Bitnami installations (if that makes a difference). My local environment is WAMP and works correctly. The second is on EC2 using LAMP and does not work correctly. I've done some basic checking and things seem to be setup the same but still give different results.
RewriteEngine On
RewriteRule ^([^/.]+)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA]
The .htaccess page is the same, as are the folder configurations. I have all files in the root folder.
-root
-index.php
-study.php
If I go to //localhost/study/ it correctly redirects to index.php. However on my EC2 instance, it instead goes to study.php. Even if I go to //ec2/study/random/2021/bleh/ it will redirect to study.php. Going to //ec2/random/ will however go correctly to index.php since I do not have a "random" folder.
I've run out of ideas of where to look for configurations differences (I even set "AllowOverride All" in the httpd.conf file and tried -MultiViews). Any help/ideas would be greatly appreciated!

Mod Rewrite tweak to ignore asset directories

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.

Rewriting URL with .htaccess local in XAMPP

My .htacces begins with
RewriteEngine on
RewriteBase /
(I tried it also without RewriteBase...)
I tried all of the following rewriting rules to rewrite the URL
index.php?page=news
to
/blog
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/blog$
index.php?page=$1 [L]
RewriteRule ^([^/]*)/blog$ /sites/blog/index.php?page=$1 [L]
RewriteRule ([a-zA-z]+)/([a-zA-z]+)/blog$ index.php?page=$1 [L]
Nothing works - no error. Mod_rewrite is installed and working. I restarted Apache and MySQL everytime I changed something in my .htaccess.
I also want to change my URLs which looks like this... index.php?page=single_news&category=release&id=9&headline=Beastie%20Boys%20III
...into: blog/release/9-Beastie-Boys-III
I am lost. Hope you can help me.
First of all, upload your .htaccess and other files (whole project) to some working, ready hosting server. And check, if your rewriting works OK there. This will let you know, if this is problem with .htaccess or XAMPP itself. I had many strange problems with using .htaccess locally, under XAMPP, that were magically gone, after files were uploaded to Internet hosting.
For example, I don't have working autorization using .htaccess locally, because right after I provide correct login and password I see exactly the same error message as you mentioned. As for me, I'm more than sure that this problem is purely related to incorrect interpretation of .htaccess done by XAMPP (as everything works like a charm on production server), not by some mistakes in .htaccess contents.
I wasted (too) many hours on finding solution and left it. For right now, if I'm developing locally, I rename ".htaccess" to "htaccess", so it is ignored by XAMPP (Apache on-board of it) and re-enable it only when deploing files to production server. This approach maybe isn't to professional, but it saved me a lot of time and stress! :]
On the other hand, if your hosting also fail with the same symptoms, then you'll know, that this is not XAMPP releated problem and you have something wrong with your syntax.
Take a look here for a similar problem reported on StackOverflow.com, where (as I think) the cause is the same as in your issue.
Here's the solution to change links from http://www.domain.tld/index.php?page=blog to http://www.domain.tld/blog is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\w+$ index.php?page=$0 [L]
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{QUERY_STRING} ^page=(\w+)$
RewriteRule ^index\.php$ /%1? [R=301,L]
and for links like: http://www.domain.tld/index.php?page=single_news&id=1&headline=This%20Is%20A%Headline
the solution is:
RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2
After using this code, links looks like this: http://www.domain.tld/blog/2-this-is-a-headline
For your first question, try this:
RewriteEngine on
RewriteRule ^/blog$ /index.php?page=news

Resources