Url Rewrite get the error message HTTP errror 500 - .htaccess

I use URL writing in the Web Server, after converting the URL provided by the user, and then passing it to the program processor in the Web Server. I have added .htaccess file in my domain folder root, like below the picture:
After I rewrite the rules in the .htaccess file, the error message is shown me:
This page isn’t working
www.everyoneknows.com.my is currently unable to handle this request.
HTTP ERROR 500
My problem sample
My website name which call is https://www.everyoneknows.com.my/customer/?loc=dashboard, this website is used PHP coding. I need to change last name ?loc=dashboard to dashboard. That means I want the result website name is https://www.everyoneknows.com.my/customer/dashboard
Below is my rewrite rules, but cannot work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^everyoneknow\.com\.my [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.everyoneknows.com.my/$1 [R,L]
RewriteCond %{HTTP_HOST} ^everyoneknows\.com\.my [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.everyoneknows.com.my/$1 [R,L]
##External redirect to /customer/dashboard url rules here.
RewriteCond %{THE_REQUEST} \s/customer/?\?loc=(\S+)\s [NC]
RewriteRule ^ /customer/%1? [R=301,L]
##Internal rewrite rules to get it served by index.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customer/(.*)/?$ index.php?parameter=$1 [QSA,NC,L]
The result is shown like below picture:
If website name is https://www.everyoneknows.com.my/customer/?loc=dashboard, the result can run well:
Hope someone can guide me on how to solve this problem. Thanks.

Related

.htaccess redirect non-clean URL with two variables to clean URL

I am trying to redirect www.bostonmabl.com/400hitter/boxscore/?SeID=332&GmID=93091 to www.bostonmabl.com/400hitter/boxscore/332/93091/ in the event that a user enters an old non-clean URL. Below is my .htacess file which I tried placing in both the 'root' directory and the '400hitter' directory, yet neither is working. Any help is greatly appreciated.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^SeID=([^&]+)&GmID=([^&]+) [NC]
RewriteRule ^/400hitter/boxscore/index\.php$ https://bostonmabl.com/400hitter/boxscore/%1/%2/? [R=301]
With your shown samples, please try following htaccess rules. Make sure your .htaccess rules file and index.php are residing in same folder.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##External redirect to new URL in browser.
RewriteCond %{THE_REQUEST} \s/(400hitter/boxscore)/\?SeID=([^&]*)&GmID=(\d+)\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
##Internal rewrite in backend.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^400hitter/boxscore/(\d+)/(\d+)/?$ index.php?SeID=$1&GmID=$2 [QSA,NC,L]
NOTE: This solution assumes that you want to rewrite(in backend) to index.php(by seeing your attempted code) and pass SeID and GmID parameters/query string into it.

hteaccess: Pretty url by htaccess showing 404 error

I am beginner in codding. I want make url pretty. I search this question on google then i found i have to use .htaccess. I tried htaccess code.
Here is my URL looklike
website.com/project-details.php?Residential/The-Serenas/1
I want to make url like website.com/Residential/The-Serenas/1
I want to remove entire "project-details.php?" word from url by htaccess.
here is my .htaccess code
Options +FollowSymLinks
RewriteEngine On
RewriteBase /basename/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /project-details\.php\?([^\s&]+) [NC]
RewriteRule ^ view/%1? [R=302,L]
RewriteCond %{THE_REQUEST} /project-details\?([^\s&]+) [NC]
RewriteRule ^ view/%1? [R=302,L]
# internally rewrites /view/ABC123 to project-details.php?ABC123
RewriteRule ^view/([A-Za-z0-9_#./#&+-]+)$ project-details.php?$1 [L,NC,QSA]
# PHP hiding rule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
Above htaccess code work and url replacce to website.com/view/Residential/The-Serenas/1
If i remove view from this line RewriteRule ^ view/%1? [R=302,L].
Then page goes to 404 error. If i dont remove view then code worked but view show on url.
I dont want to show anything on url only remove "project-details.php?" this.
This rule is to check the request uri whether is /project-details.php and any query string follow behind, and redirect user to the uri that matches the query string. %1 is the backreference and provide access to the grouped parts (in parentheses) of the pattern, in this case ([^\s&]+). For example, if uri /project-details.php?Residential/The-Serenas/1 is requested, the user will be redirected to /Residential/The-Serenas/1.
RewriteCond %{THE_REQUEST} /project-details\.php\?([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
This rule is to check if user requests existing file and directory, if not, then the uri is rewritten internally (only server knows the destination uri, user does not know this). For example, if uri /Residential/The-Serenas/1 is requested, the server will rewrite the uri to project-details.php?/Residential/The-Serenas/1.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_#./#&+-]+)$ project-details.php?$1 [L,NC,QSA]

.htaccess unblock bad redirect on get request

Here I am facing a redirection problem when I make a GET request on my new form.
On an existing hosting, I added a domain to add some forms.
My tree is:
- www
- apps.monsite.com
- b3web
- .htaccess
I do not put you, but here are the elements that concern my problem.
here is the content of my .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/b3web
RewriteRule ^(.*)$ /b3web/$1
RewriteCond %{HTTP_HOST} ^(www.)?site.fr$
RewriteRule ^(/)?$ b3web/index.php [L]
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ b3web/index.php [L]
When I access my new form with the url type: http://apps.mysite.com/monform.php, it appears correctly. If I add "? Uuid = jlerjlrjklr" I get the following redirection error:
Not Found
The requested URL /b3web/apps.monsite.com/bonsav.php&uuid=euiorprt was not found on this server.
Which is "normal" because the form is not in the "b3web" directory, and I do not understand why it is doing this redirection. How can I block this redirection without breaking the rest of the sites?
Thanks in advance
Vincent

Redirect only sub pages using htaccess

I have a website (WordPress multisite) for which I've moved a bunch of content from the route domain (http://domain[dot]com) to a sub domain (http://sub.domain[dot]com). Now I need to direct users to all the pages of the route site (http://domain[dot]com/page) to their new location (http://sub.domain[dot]com/page). But... and here's the bit I'm really struggling with... I need to omit the route url from this re-write as there is another 'geo-redirect' in place that I need to not affect. What I need to do therefore is redirect ONLY those sub page and NOT the parent/main domain.
Here's (a recent iteration) of what I'm working with:
# ignore the home page, not working :(
RewriteCond %{HTTP_HOST} !^(.*)\.routetogreatness\.com$ [NC]
# redirect all the sub pages, works
RewriteCond %{HTTP_HOST} ^routetogreatness.com [NC]
RewriteRule ^(.*)$ http://global.routetogreatness.com/$1 [L,R=301]
Any help will be very gratefully received.
I think what you are searching for is a condition that checks if the file that is requested is not a filename. That's what RewriteCond %{REQUEST_FILENAME} !-f. It is true if %{REQUEST_FILENAME} (I believe an absolute path to a file on the server, based on the request), is not a file. (Please note: I haven't tested this code as I don't have access to a server at this location, but I think it should work.)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]
An other solution would be to only rewrite the url if the requested url contains a slash. It would redirect domain.com/folder/index.php, but not domain.com/index.php.
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.+)$
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]
Okay, so the above solution didn't quite work out for me as it turned out that while this worked beautifully on sub/child page, it would skip over parent pages as well as the home page (like domain/news for example. I've eventually run with this:
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]
This just skips over the home page or root URL and redirects everything else, even 404s.

Redirecting dynamic subdomain with directory structure to a single file

I have a domain name with wildcard dns active. what i want to write in htaccess is that when the user type abc.domain.com/news/news-details.php then it should send request to the file news.php with arguments val=abc.
I have in the htaccess the following code:
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com
RewriteCond %{REQUEST_URI} ^news/news-details\.php$
#RewriteCond %{QUERY_STRING} !^id=.
RewriteRule (.*) /news.php?div=%1 [L]
But this is throwing a 404 error. what is the core part are the following two lines to explain
request for www.domain.com/news/news-details.php goes to www.domain.com/news.php
and abc.domain.com/news/news-details.php goes like www.domain.com/news.php?val=abc
Please note that i am not redirecting. the urls will show as a dynamic sub domain. physically there will be no folder. all files are located in the root.
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC]
RewriteCond %{HTTP_HOST) !^www\.
RewriteRule ^news/news-details.php$ /news.php?div=%1 [NC,QSA,L]

Resources