Mod_RewriteCond change from Apache 2.2 to 2.4 - .htaccess

My host provider is updating to Apache 2.4 and my mod_Rewrite's are failing with the new update. I've read many of the suggestions about modifying the httpd.conf or vhosts.conf however I do not have access to those files on shared hosting, and my provider will not modify to AllowOverride ALL... does anyone have any modification suggestions of the 2.2 format I am currently using to make compatible with 2.4?
Options -Indexes
RewriteEngine On
RewriteBase /mod
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} -d
RewriteCond %{SCRIPT_FILENAME}mod -d [or]
RewriteCond %{SCRIPT_FILENAME}/mod -d [or]
RewriteCond %{SCRIPT_FILENAME}\\mod -d
RewriteRule ^(.*) inc_page.php?inc_page=$1 [NC,L,QSA]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*) inc_page.php?inc_page=$1 [NC,L,QSA]

Related

Raspberry Pi web server remove .html/.php from URL

I'm using my Raspberry Pi as an webserver with a domain that i bought on strato.de with a dyndns. I attached a file named .htacces to my project with following code.
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
I also tried this one:
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.htm -f
RewriteRule (.*) $1.htm [L]
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
Before hosting my website on the webspace from STRATO.de everything worked with the first version, which you can see above. But not its only giving me an 404.
I just want to remove the ending .html/.php and other from my URL.
Log in into pi
sudo nano /etc/apache2/sites-enabled/000-default
Add:
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# AllowOverride None
Order allow,deny
allow from all
</Directory>
sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart oder service apache2 restart

Redirect to other location

I have the current setup where my file system looks like this
/var/www/blog.example.com/v1/project.php
To access project.php you go to blog.example.com/project, now I've also added a GET which is a title.
Instead of going to blog.example.com/project?title=This Title I want it to be something like blog.example.com/project/This Title
How may I accomplish that setup? Current .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^project/(.*)$ v1/project.php?title=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !/(v1)/ [NC]
RewriteRule ^(.*)$ %{ENV:BASE}v1/$1 [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
Have it like this:
# turn off MultiViews to avoid conflicts
Options +FollowSymLinks -MultiViews
RewriteEngine On
# handle /project/abcd URI
RewriteRule ^project/([^/]+)/?$ v1/project.php?title=$1 [L,QSA,NC]
# add .php extension intrnally
RewriteCond %{DOCUMENT_ROOT}/v1/$1\.php -f
RewriteRule ^(.+?)/?$ v1/$1.php [L]
# forward everything to v1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!v1/)(.*)$ v1/$1 [L,NC]
Try it like this,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([\w-]+)$ v1/$1.php
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteCond %{REQUEST_FILENAME}.php !-d
RewriteRule ^project/([\w-]+)$ v1/project.php?title=$1 [QSA,L]

Htaccess working on localhost but not on server : error 500

This is my code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !kaomadmin
RewriteCond %{REQUEST_URI} !article
RewriteCond %{REQUEST_URI} !commentaire
RewriteRule ^([a-zA-Z0-9\-]+)/?$ page/page_url?url=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !kaomadmin
RewriteCond %{REQUEST_URI} !commentaire
RewriteCond %{REQUEST_URI} !article/ajout
RewriteCond %{REQUEST_URI} !article/index
RewriteCond %{REQUEST_URI} !article/modification
RewriteRule ^article/([a-zA-Z0-9\-]+)/?$ article/article_url?url=$1 [L,QSA]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . index.php [L]
It works on localhost, but not on any of my online websites... I saw that httpd.conf AllowOverride must be set to all but i don't have that permission... and i don't see mod_rewrite on my php_info... maybe i missed something?
I tried with some htaccess tester and it works too ! I think my only problems are servers restriction... any idea?
Thanks in advance

.htaccess files not working on apache

/etc/apache2/sites-available/default.conf reads:
<Directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
I have mod_rewrite enabled
Under /var/www/sitename
I have my .htaccess file which reads:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Yet, when access localhost/sitename/directory I get a 404 error
What am I missing here?
Try adding RewriteRule ^(directory)($|/) - [L] above the first RewriteCond so it will exclude the directory from RewriteRule you can add more than 1 directory by seperating them with | like RewriteRule ^(forum|extras)($|/) - [L]
Here is an example:
RewriteEngine On
RewriteBase /
RewriteRule ^(directory)($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
For people using ubuntu I found this answer to be complete.
https://askubuntu.com/a/48363
try this -
Options +FollowSymLinks
RewriteEngine on
RewriteRule process-id-(.*)\.htm$ process.php?id=$1

Add another exception to htaccess?

My .htaccess file alows access to real files & folders on the server. For anything else, it will redirect to /index.php, except when the app folder is specified in which case it will redirect to /app/index.php. I want to add a second folder named appbeta which will redirect to /appbeta/index.php. How should I modify my .htaccess to add this additional exception?
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app(.+)$ /app/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I am not exactly sure what the following rewrite does:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
However, if your current .htaccess is working as you want, I would try the following which puts a rewrite for /appbeta right before the rewrite for /app:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
# rewrite /addbeta to /appbeta/index.php ...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^appbeta(.*)$ /appbeta/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app(.+)$ /app/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
note: no new question started as mentioned in comments, fix above (change ^appbeta(.+)$ to ^appbeta(.*)$)

Resources