Can't goto root of website anymore - php

I'm making a new website and had lots of help overhere before with the htaccess to make it all work. Nevertheless I can't reach the root of the website www.placewomen.com anymore...it's looking for /c/c when I aspect the index.html of the root....My htaccess looks like this:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^placewomen.com [NC]
RewriteRule ^(.*)$ http://www.placewomen.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/+new/index\.php\?var=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{DOCUMENT_ROOT}/c/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/c/$1 -d [OR]
RewriteCond %{DOCUMENT_ROOT}/c/$1 -l
RewriteRule ^(.*)$ /c/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /new/index.php?var=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/placeholder.jpg -f
RewriteRule ^(.*)$ /$1/placeholder.jpg [L]

Try this code:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^placewomen\.com$ [NC]
RewriteRule ^(.*)$ http://www.placewomen.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/+new/index\.php\?var=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/placeholder.jpg -f
RewriteRule ^(.*)$ /$1/placeholder.jpg [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/c/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/c/$1 -d [OR]
RewriteCond %{DOCUMENT_ROOT}/c/$1 -l
RewriteRule ^(.+)$ /c/$1 [L]
RewriteRule ^(.+)$ /new/index.php?var=$1 [QSA,L]

Related

how to combine 2 .htaccess rewrites

I have 2 different rewrites in my .htaccess file that I need to combine into 1.
The first redirects all requests to the https://www version of the website.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^w3studios\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$
RewriteRule ^(.*)$ "https\:\/\/www\.mywebsite\.com\/$1" [R=301,L]
</IfModule>
The second gets all the post data and assigns to a variable.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
How can I combine these to both work?
Thank-you
You can use this combined set of rules in your site:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

ErrorDocument, remove .php and force https .htacces

I have
ErrorDocument 404 https://demo.com/404
#Remove .php
Options Indexes FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.php
#Force https and without www
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
This isn't work ErrorDocument 404, I want you to do this:
www.demo.com -> https://demo.com
www.demo.com/page-not-exits -> https://demo.com/404
www.demo.com/page.php -> https://demo.com/page
http://demo.com -> https://demo.com
Greetings and thank you!
Solution
Finally this works:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [R=301,L]
#errorredirect
ErrorDocument 404 http://demo.com/404.php
#remove .php
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
</IfModule>
thanks #rushil-pachchigar
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#errorredirect
ErrorDocument 404 http://example.com/404.php
#remove .php
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
</IfModule>
You can use the following htaccess
ErrorDocument 404 https://demo.com/404
RewriteEngine on
#force https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://demo.com/$1 [L,NE,R]
#remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]
Try below rules,
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ 404 [R=301,L]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([\w-]+) $1.php [L]

.htaccess redirect loop error

I created a .htaccess with the following goals:
1: Remove .php and force add trailing slash
2: Make http://website.com/sticker/fruit/apple = sticker.php?category=fruit&alt=apple
That works, but whenever I type something that does not exist, for example:
http://website.com/sdgsdg/ OR
http://website.com/dssdg/sdgsg/zkzzv/
I get redirect errors.
Here is my .htacess:
Options +FollowSymlinks
RewriteEngine on
# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php/$ http://website.com/$1/ [L,R=301]
# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ http://website.com/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ http://website.com/$1/ [L,R=301]
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^sticker/([^/.]+)/([^/.]+)/$ sticker.php?category=$1&alt=$2 [NC,L]
Can anyone spot whats causing the redirect loops?
Thank you in advance.
I found a solution that worked for me.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^sticker/([^/.]+)/([^/.]+)/$ sticker.php?category=$1&alt=$2 [NC,L]

Use Two rules for Htaccess

This line is working
RewriteRule ^(.*)/(.*)?$ site/$1/pagina.php?pagina=$2 [L]
Now I'm trying to make when accessing the link /inicio go to the index.php page.
RewriteRule ^inicio/(.*)?$ site/$1/index.php [L]
Thereby
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^site/
RewriteRule ^inicio/(.*)?$ site/$1/index.php [NC,L]
RewriteRule ^(.*)/(.*)?$ site/$1/pagina.php?pagina=$2 [L]
.
.
.
.
Current code, with the help of friend #anubhava
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/site/ [NC]
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/inicio?$ site/$1/index.php [NC,L,QSA]
RewriteRule ^([^/]+)/noticia/([^/]+)/?$ site/$1/pagina.php?pagina=pag_noticiasVer.php&id=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ site/$1/pagina.php?pagina=$2 [L,QSA]
Have it this way:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/site/ [NC]
RewriteRule ^ - [L]
RewriteRule ^inicio/([^/]+)/?$ site/$1/index.php [NC,L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ site/$1/pagina.php?pagina=$2 [L,QSA]
RewriteCond are only applicable for next RewriteRule.

.htaccess doesn't rewrite the URL as it should

I have the following .htaccess file:
RewriteEngine On
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]
RewriteRule ^search/([^/]+)/?$ search.php?q=$1
RewriteRule ^user/([^/]+) user.php?proc=$1
When I go to: http://localhost/user/register/, and try to echo the variable $_GET["proc"], I get: register.php instead of register. Where is my mistake?
Ordering of your rules seems to be a problem here.
Keep your .htaccess like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteRule ^search/([^/]+)/?$ /search.php?q=$1 [L,QSA]
RewriteRule ^user/([^/]+) /user.php?proc=$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/$ /$1.php
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L]

Categories