Good day,
I want to rewrite my user id URL to a physical page on my website.
This is a login PHP MySQL system and each user (client) has an ID assigned to them in MySQL. I want to give each user (client) a unique home page
So the client list are as follow:
Client1 - Client ID = 341
Client2 - Client ID = 342
Client3 - Client ID = 343
Currently, the user login to the site and gets redirected
from:
http://localhost:8888/report.mark1/user.php?id=341
to:
http://localhost:8888/report.mark1/341 (this works perfectly)
But I want to change this to the following:
From: http://localhost:8888/report.mark1/341
To: http://localhost:8888/report.mark1/client1/home
I want to do this for the other clients as well:
From: http://localhost:8888/report.mark1/user.php?id=342
To: http://localhost:8888/report.mark1/client2/home
From: http://localhost:8888/report.mark1/user.php?id=343
To: http://localhost:8888/report.mark1/client3/home
this is the current .htaccess file code:
RewriteEngine ON
RewriteBase /report.mark1/
##External redirect change of URL rules here.
RewriteCond %{THE_REQUEST} \s/(report\.mark1)/user\.php\?id=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to user.php rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)(\d+)/?$ /report.mark1/user.php?id=$1 [QSA,L]
I hope this helps a bit more :)
With your shown samples, attempts please try following .htaccess rules. Make sure your .htaccess file is present alongside with report.mark1 folder and your user.php is present inside report.mark1 folder.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /report.mark1/
##External redirect of url in browser rules here...
RewriteCond %{THE_REQUEST} \s/(report\.mark1)/user\.php\?id=(\S+)\s [NC]
RewriteRule ^ /%1/%2/home? [R=301,L]
##Internal rewrite of url to user.php file here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)/([^/]+)/.*/?$ /report.mark1/user.php?id=$1 [QSA,NC,L]
Related
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.
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.
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]
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
We have a server, and have several folders under the /var/www/ folder.
We have pointed our domain name to the IP of the server, and by default we expect to load one folder as the website (since its not possible to point a folder with DNS).
I have written .htaccess in such a way that when you enter the IP or the domain name, the request redirects to the website folder.
However, whenever we enter the IP or the domain name, the name of the folder is getting added to the URL.
Here is the present .htaccess:
Options +FollowSymlinks -Multiviews
#DirectoryIndex folder/
RewriteEngine on
ReWriteBase /
RewriteRule ^$ /folder [L]
RewriteRule ^$ folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folder/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^folder/)^(.*)$ /folder/$1 [L,NC]
where the folder is the folder's website
so,
www.domain.com
becomes
www.domain.com/folder/
Is there a way to rewrite the URL to remove the folder name?
Thanks in advance :)
EDIT : Added .htaccess code
Have your rule like this in DocumentRoot/.htacess:
DirectorySlash On
Options +FollowSymlinks -MultiViews
RewriteEngine on
ReWriteBase /
# redirect /folder/abc123 to /abc123
RewriteCond %{THE_REQUEST} \s/+folder/(\S*) [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# skip rewrites for real files/directories
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule !^(index\.)?$ - [L]
# route everything internally to /folder
RewriteRule ^((?!folder/).*)$ folder/$1 [L,NC]
It sounds like you made an external redirect instead of an internal rewrite. An external redirect is denoted by the [R] flag (with optional parameter) and causes Apache to send a 301 or 302 header back to the client with a different url that client should request. This causes the client to show the new url in the address bar.
What you want is an internal rewrite. When you request the url, the url is internally rewritten to the place where the resource is actually located. You do this by omitting the [R] flag, and not using a domain name in the rewritten part. It typically looks something like this:
RewriteCond %{REQUEST_URI} !^/folder
RewriteRule ^(.*)$ /folder/$1 [L]