I am using PHP in a Google cloud compute engine container. The following .htaccess code should retrieve a query string param g - but somehow there is no query string parameter that is being retrieved.
Options +FollowSymlinks
Options All -Indexes
RewriteEngine On
RewriteRule ^([^/]+)(.sh)/?$ index.php?g=$1 [QSA,L]
By way of example:
http://example.com/dir/dallas.sh should be able to retrieve dallas as the value of query string parameter g? But it is not doing that?
The .htaccess file with the rewrite code is in the subdirectory dir with index.php that is looking for the query string parameter g.
I have tried to test if .htaccess itself is working. I can prevent directory browsing by putting in the code in the .htaccess file for the directory:
Options -Indexes
Thanks #w3dk - this is now working. Mod_rewrite module loads in httpd.conf. I restarted the apache server. I am able to now retrieve Dallas from the querystring. No idea if I was doing something wrong. No idea if there was something reset by Google Support. Is any one familiar with similar intermittent on-off on querystring retrieval from htaccess in apache on google cloud. They officially DO NOT support htaccess in their app-engine containers or in firebase. Curious. Any way? false alarm. Thanks a lot #w3dk for your responses.
Related
I have a URL that looks like this: https://www.example.com/users.php?username=Name. Instead of this I want it to look like this: https://www.example.com/users/username=Name. What are the steps to aquire this? I have tried searching, but I just cannot figure out what to search to find the answer.
It depends if you're using an apache server you can acquire this with .htaccess, in that case you could use RewriteEngine On with the specific RewriteRule.
.htaccess file in the root of you're website/domain:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^users/username=(.*)$ /users.php?username=$1
Beside this there are a lot of more options and flags with htaccess rewriterule
If you're using nginx it will be done on the nginx way, you may use an converter from htaccess to nginx of fins some more information for nginx rewrite url.
I try to making work a php site on my NAS Synolgy DS916Play.
The problem I have is I need to rewrite all api call to index.php with in form:
Initial call: controller/action?queryParams final call:
api/index.php?route=controller/action&queryParams;
I try to put a .htaccess in site folder, but Apache didn't read this file (I put something wrong there, and no error occurred).
SO I need help in two problem:
Configure Apache on NAS, to read .htaccess,
A .htaccess file for what I need.
I have a version, but I'm not sure if it's correct:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([\w\/\-]+)/?$ api/index.php?_route_=$1 [QSA]
</IfModule>
Or if someone has other solution, I'm glad to hear it.
The site is One page application angularJS with backend php.
I doubt even it is possible or not. I have a strange requirement by client so have to do.
I have a website that allow certain ips(ips are hard coded in .htaccess ). Client has provided me a url that have some ips listed in json format. I want that these ips should be allowed to access the website. (Ips listed on url are dynamic so i can't use them in .htaccess). Do anyone have idea how to achieve this.
I know i can use a php file(index) in htaccess and write code in it to read ips but the priority is to get it done by .htaccess file only.
Thanks in advance.
Need little bit help.
I have created rewriteMap in httpd file.
RewriteMap accessmap "txt:E:\htdocs\myfolder\map.txt"
My map.txt have follwing entries.
127.0.0.11 allow
127.0.0.1 allow
127.0.0.12 deny
These entries i am adding in htacces file
RewriteCond ${accessmap:%{REMOTE_ADDR}} allow [NC]
RewriteRule ^(.*)$ https://www.exampleweb.com/$1 [L,R=302]
Now, for example i have 127.0.0.1 in my map file as allow so it should be allowed to access the site. If i want to access site form any other ip like
130.0.0.11 (not in map file) it should be redirect to this link https://www.exampleweb.com .
I do not have much knowledge about htaccess to can't understand how to write
rewriteRule and rewrite condition for this. Please help.
Note: Ips are just for example, actual ips will be different for these.
Create a RewriteMap. Add below code in Apache configuration file (httpd.conf) or in your virtual host file.
RewriteMap accessmap "txt:file/path/to/map.txt"
NOTE: RewriteMap directive cannot be added in .htaccess file or inside Directory section. [Source: Using rewrite map]
Then in your .htaccess file add below code
RewriteCond ${accessmap:%{REMOTE_ADDR}} !^allow
RewriteRule ^(.)$ - [F,L]*
This will allow IP addresses listed in map.txt file having value allow to access your site. Otherwise, users will see 403 forbidden error.
.htaccess files are constantly read by Apache HTTPD server. You can be changing the specific Authorization directives in it according to your needs by a script or something else and the new auth directives will be applied instantly.
So i have been try to figure out how to make my link search engine friendly and i have learned so far that the .htaccess file has to be in the root directory of the website Folder. The following is the contents of the folder which i think it has an error because it keeps getting hidden from the wamp server
RewriteEngine On
Options FollowSymLinks
RewriteRule ^(([a-zA-Z0-9])*\/([a-zA-Z0-9])*)*$ $1.php?article=$2
Now i am trying to do the following.
Turn this link :http://localhost:63342/EuroSkills/View/Beer.php?article=6
Into this link http://localhost:63342/EuroSkills/View/Beer6
What i am changing is that beer.php file into just beer
They way I handled URLs in an old PHP application I had, is to map ALL urls to index.php. Then use PHP code to parse out $_REQUEST the path that was requested, and make the decisions there.
Place code in your /EuroSkills/.htaccess file:
RewriteEngine On
RewriteBase /EuroSkills/View/
RewriteRule ^([a-z]+)([0-9]+)/?$ $1.php?article=$2 [L,NC,QSA]
In my php web site, I need to display my urn in a specific manner
I need to hide the query string parameters and just want to display the value in the URL
i.e.
mydomain.com/city.php?place='usa'&id=2
I need to display
my domain.com/city-2/usa
Is it possible?
Please help me. I am in a serious situation.
Thanks in advance
Yes, it is possible:
RewriteEngine On
RewriteBase /
RewriteRule ^city-(\d+)/(.*) city.php?place=$2&id=$1
You need to put it into the .htaccess placed in the web root of your site. To get it worked you need to have .htaccess parsing enabled and mod_rewrite apache module (assuming you have apache as a web server) enabled as well.
More in official documentation