Why does this site return http 404? - apache

this is my htaccess:
RewriteEngine On
RewriteBase /
RewriteEngine on
RewriteCond %{HTTP_HOST} ^slople.com$
RewriteRule (.*) http://www.slople.com/$1 [R=301,L]
# pass the default character set
AddDefaultCharset utf-8
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:.+/)?(\d+)/?$ index.php?slopeId=$1 [L,QSA]
#only rewrite if it's not a file and not /login/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/community/
#Wordpress-Regeln
#RewriteBase /community/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /community/index.php [L]
</IfModule>
Why does the URL http://www.slople.com/deutschland/hessen/buseck/alter-steinbruch/14231?language=DE, which should match this rule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:.+/)?(\d+)/?$ index.php?slopeId=$1 [L,QSA]
return a http 404?
I thought the "[L]" would stop execution of the later rules in htaccess?
Thanks
Raphael

Related

.htaccess file not working properly in ionos. My website- https://rentocure.com

I want to have clean link like- https://rentocure.com/doctors/rc635502e5e9376 instead of https://rentocure.com/doctors.php?uid=rc635502e5e9376 (U can go through my website). I have the following code in localhost
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)/$ $1 [L,R=301]
RewriteRule ^/?home/([^/]+)?$ "index.php" [L,QSA]
ErrorDocument 404 https://rentocure.com/404/
RewriteRule ^doctors/([^/]*)$ doctors.php?uid=$1 [L]
RewriteRule ^hospitals/([^/]*)$ hospitals.php?uid=$1 [L]
which is working fine in localhost but not in ionos apache server so I changed it to the following:
Options +MultiViews
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#Redirect to SSL Secured Page
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://rentocure.com/$1 [R=301,L]
#Removing File Extension .php and adding trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
#Custom 404 Page
ErrorDocument 404 https://rentocure.com/404/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^doctors/([^/]*)$ doctors/?uid=$1 [QSA,L]
But still it is not working kindly check my website and give me the solution. For the one whose solution will work for me will get assured cash reward from me.
Expecting solution through .htaccess code.

How to create multiple rewrite rules in .htaccess

I want to have this kind of structure in .htaccess. Is it possible?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^signup$ /signup.html [L]
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^signin$ /signin.html [L]
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^home$ /landing.html [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]
</IfModule>
For landing, signin, signup I want to request separate pages and for all other requests I need to request index.html page. Can I do that with .htaccess?
Have it like this:
DirectoryIndex index.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} /index\.html$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(signup|signin)/?$ $1.html [L,NC]
RewriteRule ^home/?$ landing.html [L,NC]
RewriteRule . index.html [L]

WAMP nice URL's redirect to direct file

Hello when I trying nice url with htaccess it's redirecting to file, so when I type www.page.com/mainpage it's redirect to www.page.com/mainpage.php and not to www.page.com/index.php?arg1=mainpage
my .htaccess looks like
RewriteEngine On
RewriteBase /
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ ?arg1=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^([^/]+)/([^/]+)?/?$ ?arg1=$1&arg2=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?/?$ ?arg1=$1&arg2=$2&arg3=$3 [L,QSA]
You probably have the MultiViews enabled. Also, your rewrites are not referencing index.php anywhere. Try the following:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?arg1=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^([^/]+)/([^/]+)?/?$ index.php?arg1=$1&arg2=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?/?$ index.php?arg1=$1&arg2=$2&arg3=$3 [L,QSA]

ModRewrite remove /index.php/

I've got old urls and want to remove the /index.php/ via .htaccess:
So old url is:
www.mysite.com/index.php/onesite.html
rewrite in .htaccess into
www.mysite.com/onesite.html
How can I do that?
Thx for your help
Adding the following code to your htaccess will allow this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index.php/(.*)$ www.mysite.com/$1 [R=302,L]
Changing 302 to 301 when you are sure the redirect is working
Try this one:
RewriteRule ^index.php/(.*?)$ http://%{HTTP_HOST}/$1 [R=301,L]
Just add this in your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
If you site is in subfolder then
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
</IfModule>
You can use these 2 rules in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^index\.php(/.*)?$ $1 [L,R=301,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ /index.php/$1 [L]

htaccess trailing slash not working

I have the below code in my htaccess. The site works fine (ie: no 500 errors) but it is not adding the trailing slash to my URLs:
<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 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://staging.foo.com/$1/ [L,R=301]
</IfModule>
What do I have wrong here?
You need to swap the order of your rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://staging.foo.com/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php?$1 [NC,L]
</IfModule>
The reason why it wasn't working was because the routing to /index.php rule was being applied first, then the rewrite engine loops, and then the 2nd rule (the redirect rule) won't get applied because the URI has been rewritten to /index.php and that causes the %{REQUEST_FILENAME} !-f to fail, since index.php exists, thus, the redirect never happens.