I have public html folder where some files and folders are stored. Then I have created a Folder In It. That Folder Contains Some Files And A Folder "Admin" which containes files related to my admin panel to surf my site members data.
Now I used Following Code In .htaccess file in public html folder which removes all pages's php extension.But When I try To Log In To My Admin Panel, Log In Fails.
e.g. www.abc.com >> Here .htaccess file Is with following code.
It works For Files in www.abc.com and for files in www.abc.com/xyz/index.php and other files. But When Tried www.abc.com/xyz/admin/index.php For Login, This Page just get refreshed But Doesn't allowing successful login.
Code used in .htaccess is as follows :
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
Try these rules that avoid redirecting for POST requests:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.(?:php|html)[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]
Related
Hi everyone i need help about htaccess. I am trying to make a facebook style profile url like : https://www.example.com/azzo
So the user_profile.php is in the pages folder. Now user profile link is this http://www.example.com/pages/user_profile?username=azzo So i want to cut the pages file name from the url. What should i do to use my url like facebook (https://www.example.com/azzo) .
I am using the following htaccess
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]
RewriteRule ^group/([\w-]+)/?$ pages/group.php?group_username=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^(.+?)/?$ index.php?pages=$1 [L,QSA]
What should i do to change the url like this:
http://www.example.com/pages/user_profile?username=azzo
to this
https://www.example.com/azzo
I have tryed the following rule:
RewriteRule (?:^|/)([\w-]+)/?$ pages/user_profile.php?username=$1 [L,QSA]
after the
RewriteRule ^(.+?)/?$ index.php?pages=$1 [L,QSA]
but i get blank page.
I am redirecting
https://www.example.com/inter.php?pid=<a number>&title=<the page title>
to
https://www.example.com/<a number>/<the-page-title>
Now I want to move the website to a sub folder so the redirection will be
https://www,example.com/folder/inter.php?pid=<a number>&title=<the page title>
to
https://www.example.com/folder/<a number>/<the-page-title>
I am using the below .htaccess code
RewriteEngine On
RewriteCond %{THE_REQUEST} /inter\.php\?pid=([^&\s]+)&title=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,NE,L]
RewriteRule ^(\S+)\s+(.*)$ $1-$2 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^(\S+)$ /$1 [NE,R=302,L]
RewriteRule ^([^/]+)/([^/]+)/?$ inter.php?pid=$1&title=$2 [L,QSA]
Please Suggest.
thanks!
If you are using .htaccess in root directory you can add /foldername
RewriteCond %{THE_REQUEST} /folder/inter\.php\?pid=([^&\s]+)&title=([^\s&]+) [NC]
RewriteRule ^ /foldername/%1/%2? [L,R]
To both rules
RewriteRule ^folder/([^/]+)/([^/]+)/?$ inter.php?pid=$1&title=$2 [L,QSA]
Please try above rules it I didn't tried it for now.
I am trying to just update my .htaccess file so that I get nicer looking url's (without the file extenstion of .php). The file already has a redirect in it as I have both domain names.
Here is the original code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^darrenmorton\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.darrenmorton\.com$
RewriteRule ^/?$ "http\:\/\/darrenmorton\.co\.uk\/" [R=301,L]
And here is my updated code that is not working
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^darrenmorton\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.darrenmorton\.com$
RewriteRule ^/?$ "http\:\/\/darrenmorton\.co\.uk\/" [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
Not
RewriteCond %{REQUEST_FILENAME} \.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^contact-darren-morton.php$ contact-darren-morton.php [L]
Not sure what is the problem as I am new to .htaccess files!
You can use:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?darrenmorton\.com$ [NC]
RewriteRule ^ http://darrenmorton.co.uk}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
You are redirecting everything with that statement:
RewriteRule ^/?$ "http\:\/\/darrenmorton\.co\.uk\/" [R=301,L]
Nothing after that will ever work, because it is the last rule to be checked if it matches (and it matches always). Defined by you with the [L].
So at least you need to change the order of your rules. If you want the rules to only work on your .co.uk domain you have other options, too.
I have site xyz.com with index.php page And there is a subfolder in rootfolder.
e.g. folder viz. "audio" which contains index.php and other pages.
Now problem is When I opened www.xyz.com/audio it opens but when i navigate in this audio folder through navigation menu and try to return to audio/index.php by clicking link in navigation bar in audio folder, it brings me to www.xyz.com/index.php instead of www.xyz.com/audio/index.php. But other pages navigation in audio folder works perfectly.
I have used .htaccess in root folder and in audio folder too with following rules (Used to remove file extension). Is it creating this error ? Or any other thing? I got stucked..
RewriteEngine On
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.(?:php|html)[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]
I'm using the following code in the .htaccess file to hide the extension of the php file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ ([^\.]+)$ $1.php [NC]
I placed this file in the localhost/obis/
But when I run the index.php file without the .php extension, the following error occurs.
The requested URL /obis/index was not found on this server.
Can anybody suggest what might be the error?
I took the code from this tutorial: http://www.youtube.com/watch?v=L6k_WvvpPpk
Try these 2 rules in root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]