Trying to append and access $_GET parameters in a rewritten url. Currently redirecting. Htaccess
I have rewritten my urls from the following: eg
https://website.com/search.php?number=00000000000
to the following:
https://website.com/number/00000000000
But now I wish to pass ?success=1 to my rewritten urls. But when I do it redirects:
https://website.com/number/00000000000?success=1
to
https://website.com/number/00000000000
How can I achieve this?
Here's my htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} \.(jpg|css|js|gif|png)$ [NC]
RewriteRule ^ - [L]
#unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
#resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
#redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php /$1 [R=301,L]
RewriteRule ^number/([^/]*)$ /search.php?number=$1 [L,QSA]
See also questions close to this topic
-
non-www http version has two redirects in wordpress
I have a short issue of one of my sites. I checked all redirects with httpstatus.io All redirects are working without any issues, the only one which causes problem is the non-www http version of the site.
It first redirects to https non-www then to https www. I am trying to fix it since days but did not work. Is it bad for google? I am using cloudflare SSL and this are my first lines in htaccess file:
# BEGIN WpFastestCache <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTPS} =on RewriteCond %{HTTP_HOST} ^www.my-domain.net # Start WPFC Exclude # End WPFC Exclude # Start_WPFC_Exclude_Admin_Cookie
after that i have this lines
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=admin # End_WPFC_Exclude_Admin_Cookie RewriteCond %{HTTPS_HOST} ^www.my-domain.net RewriteCond %{HTTP_USER_AGENT} !(facebookexternalhit|LinkedInBot|WhatsApp|Mediatoolkitbot) RewriteCond %{HTTP_USER_AGENT} !(WP\sFastest\sCache\sPreload(\siPhone\sMobile)?\s*Bot) RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{HTTPS} !=on
hope you can help
-
Docker container routing
I'm trying to use docker/docker-compose to implement a webserver where part of my pages are served by PHP, and part are served by Java. So, when I connect to
localhost/php-service
, i'd get routed to a container running a PHP server, and connecting tolocalhost/java-service
would redirect me to the container running the Java webserver.My first approach to this, which might be wrong, was to have a separate container running apache and to use mod-rewrite to redirect me to the appropriate container. Before trying anything fancy I simply tried redirecting to my php server container using its ip:
#.htaccess RewriteEngine on RewriteRule .* http://192.168.128.6/ # <- IP address of container with webserver
This isn't working, as my browser simply rewrites the url to "192.168.128.6" and then complains about not finding the IP. Apparently the rewrite engine just tells the browser to go somewhere else, it doesn't actually forward the request. I could assign a different port to each server and have the rewrite engine forward to the appropriate port, but i feel like there must be a more elegant way of solving this. I've been looking at using iptables but it also doesn't feel like the right tool for the job...
Thanks in advance for any help.
-
Show content of subdomain with htaccess
One of my subdomains, 'sub1.domain.com', points to an IP address where X website is located. I have multiple subdomains and each subdomain points to the specific IP address. So, here's what I want to do: when someone head overs to 'domain.com/sub1' I would like to provide him content from 'sub1.domain.com' but without chaning URL, so it's still 'domain.com/sub1'. Also, as multiple subdomains will be used, I would also like to show content of 'sub2.domain.com' on 'domain.com/sub2' aswell, and so on. I've been googling for some time but none of the results helped me. I would like to thank you in advance.
-
Convert htaccess rule to nginx
I have the following rule in apache .htaccess:
RewriteCond %{DOCUMENT_ROOT}/webroot/files/verification/$1 -f
RewriteRule (.*) files/verification/$1 [L]All files in directory files/verification/{request_file} accessible by the following link site.com/request_file
How can I configure it on nginx?
-
Rewrite rule for images using .htaccess or nginx config
we need to set rewrite rule for some images using .htaccess rules or nginx conf
Example 1
Request Path:
Response Path:
https://www.example.com/pub/media/catalog/product/cache/543x403/n/u/number1.png
Example 2
Request Path :
Response Path :
https://www.example.com/pub/media/catalog/product/cache/543x403/l/e/legal_slide01.jpg
Here the
l/e/
directories are set according to the first two characters of image name here:legal_slide01.jpg
Thank you
-
.htaccess Issue on "Deluxe" Hosting
So I'm no .htaccess guru. I barely understand what's going on. I have a shared hosting account on GoDaddy that allows for unlimited domains to be hosted. (I know, GoDaddy isn't my best option)
The primary domain files are located in the root directory and add on domains are in sub directories.
My main site is using a custom MVC Framework. I have two directories in it, app, and public, and an .htaccess file telling it to go to the "public" directory. I think this file is causing my issue (500 errors on my other sites)
Here is my .htaccess file:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] </IfModule>
My question is, is there a change I can make so that it doesn't effect my other sites? Is it something I'd have to change each time I add an add-on domain? Any help would be greatly appreciated.
-
How to redirect a string with starts with double quote and have special chars in apache2?
I've been implementing redirects for a client.We came across a url something like domain.com/"https://www.youtube.com/watch?v=....". (exactly like this - starting with double quote after the backslash)
I tried a lot of regex and other rules but couldn't get this done.I tried
Redirect 301
also tried to encode double quotes in Redirect 301 directive with %22.Tried couple of regex found on internet, but nothing is worked.
I do not have much knowledge on redirects on apache2.Please help guys here.
Thanks in advance.
-
Make ? invisible in blog URL using URL Rewrite
I need a URL Rewrite which will prevent the ? from showing up in the URL when people go to my blog. Basically, invisible to the user.
Going to my example.com/blog/ correctly displays without a question mark in the URL and correctly displays all of my blogs allowing people to click on a blog of their choice. When they do, they get a ? in the URL like these for example.
example.com/blog/?productivity
example.com/blog/?known-and-unknown
examplecom/blog/?hacked
example.com/blog/?hidden
example.com/blog/?confidentiality etc.
I would like for everything in /blog to appear without the ? showing in the URL like this:
example.com/blog/productivity
example.com/blog/known-and-unknown
examplecom/blog/hacked
example.com/blog/hidden
example.com/blog/confidentiality
I noticed that if I remove the ? from the url, it takes me to example.com/blog/index.php which shows my blogs. When I click on a blog from there, I get these for example:
example.com/blog/index.php?productivity
example.com/blog/index.php?known-and-unknown
example.com/blog/index.php?hacked
example.com/blog/index.php?hidden
example.com/blog/index.php?confidentiality
One last thing I noticed: example.com/blog/ is the same as example.com/blog/? in that they both bring up my list of blogs for people to click on.
That's all of the info I have.
Is there a rewrite which can address this?
Any ideas? Thank you.
-
IIS Rewrite SEF Urls with subfolders
I've searched around quite a bit without any luck so decided it was time I asked.
I have a situation where a client wants SEF urls
www.somesite.com/sef_rewriting
www.somesite.com/foo
work fine - the problem is that what happens if
sef_rewriting
can also be a directory?www.somesite.com/sef_rewriting/removing_file_extensions
IIS will automatically add a trailing slash if someone requests the following url:
www.somesite.com/sef_rewriting
and redirect to the sub-directory.How do I create a rule to check to see if the requested extensionless URL matches a file with a specified extension say in this case (html) and serve up that file and only if the file doesn't exists should IIS redirect to the sub-directory?
I found the following rule online it works for the basic case but not with subdirectories with the same name as files.
<rule name="SEF REWRITE html"> <match url=".*" negate="false" /> <conditions> <add input="{URL}" pattern="(/[^.]*|\.(html))$" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="{C:0}.html" /> </rule>
any help would be appreciated..
note: the file and directory naming scheme can not be changed.