I am trying to post form in core php and custom .htaccess file. When I am posting my form, it redirects to the posted page but didn't act with the php functions.
All other pages are working well dynamically, only form submission has an issue.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.werepairuae.com
RewriteRule (.*) http://werepairuae.com/$1 [R=301,L]
#form submit------------------
#RewriteRule ^([a-zA-Z0-9-/]+).php$ prob-page-dtls_post.php [QSA,L]
#RewriteRule ^([a-zA-Z0-9-/]+).php/$ prob-page-dtls_post.php [QSA,L]
RewriteRule ^([a-zA-Z0-9-/]+).php/$ prob-page-dtls_post.php [QSA,L]
#-----------------------------
Here is my code sample, how can I fix this issue?
You need to do the redirect differently for POST requests. Try:
RewriteRule ^([a-zA-Z0-9-/]+).php/$ prob-page-dtls_post.php [NC,P]
"Use of the [P] flag causes the request to be handled by mod_proxy, and handled via a proxy request."
https://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
Checkout these other questions for relevant discussion with redirecting POST requests:
Is it possible to redirect post data?
Redirect POST htaccess
Thank to all of you, specially who answer me, after searching on his answer i get this one to add in my .htaccess file and i found my result. And that is i have successfully submit my form and email.
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www.werepairuae.com
RewriteRule (.*) http://werepairuae.com/$1 [R=301,L]
RewriteRule ^([a-zA-Z0-9-/]+).php/$ prob-page-dtls_post.php [QSA,L]
i Just added these 2 lines on my file
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
and it works.
Thanks to every one!
Related
I am currently working on a project where I have to redirect a user after a form has been submitted.
Once the form is submitted I redirect the user to a url based on what they entered into the form. An example of what the URL might look like:
/oslo-norway-copenhagen-denmark
I would like /oslo-norway-copenhagen-denmark to display in the users URL bar, would would like it to represent the page /page.php?id=oslo-norway-copenhagen-denmark.
I've currently got this working:
Options +FollowSymLinks
RewriteEngine On
DirectoryIndex search.php
RewriteBase /services
RewriteRule ^formmail/([^/]*)$ formmail.php?id=$1 [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
The only problem is that this makes /formmail/oslo-norway-copenhagen-denmark work, but how do I go about making this only /oslo-norway-copenhagen-denmark? I tried removing the /formmail/ but this didn't work
Could anyone help me solve this problem? Thank you very much!
All you need to use is this in your .htaccess file:
RewriteEngine On
RewriteRule ^([^/]*)$ /services/page.php?id=$1 [L]
Make sure you clear your cache before testing it. It will leave you with your desired URL.
Im trying to achieve this
http://domain.com?q=page-slug to http://domain.com/page-slug
right now if I access this http://domain.com?q=page-slug my webpage is working, but I want clean URls like http://domain.com/page-slug
I used this code in my htaccess but returning 500 error
RewriteEngine On
RewriteRule ^(.*)$ ?q=$1 [L,QSA]
any help please.
Try this I am assuming you have index.php page which is handling the request.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ index.php?q=$1 [QSA,L]
If not index.php change to actual page you have.
this is my .htaccess code
here in last line i redirect my user with a variable . it redirect successfully for example
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?technotch.in [NC]
RewriteRule .(jpg|jpeg|png|gif)$ - [NC,F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-_]+)$ $1.php [QSA,NC,L]
RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ $1.php?product=$2 [QSA,NC,L]
</IfModule>
(http://technotch.in/Online-Certification/abc)
to
(http://technotch.in/Online-Certificate.php?product=abc)
but on my php page the variable product in not getting with the code
$_GET['product'];
i has been check my .htaccess redirection on (htaccess.madewithlove.be)
here it resolve it redirect url completely
so please guide me what i do?
From what I can see, your RewriteRule works as follows:
http://www.website.com/page is interpreted as http://www.website.com/page.php
and
http://www.website.com/xxxx/xxxx/page/item is interpreted as http://www.website.com/page.php?product=item
Is this what you are trying to achieve?
EDIT:
Apologies, I read it incorrectly, try doing a var dump on the requested page and see what vars you get.
Also, try changing [QSA, NC, L] from both to [QSA] since [L] means that it should stop processing any other rules below.
I'm trying to accomplish 2 things in my .htaccess:
Redirect all requests for (in example) www.blanklabs.com/boarddrive/faq, www.blanklabs.com/boarddrive/faq.htm, www.blanklabs.com/boarddrive/faq.html, or www.blanklabs.com/boarddrive/faq.php to www.blanklabs.com/boarddrive/faq.php
The browser's address bar should show just www.blanklabs.com/boarddrive/faq, without the extension.
Here is my current .htaccess:
RewriteEngine On
# -- new
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php [L,QSA]
On the server I have faq.html (for now), but I also tried having both faq.html and faq.php. Eventually it'll just be faq.php.
The .htaccess is clearly incorrect, since if I go to www.blanklabs.com/boarddrive/faq.html I get the correct content (from faq.html), but if I go to www.blanklabs.com/boarddrive/faq.php I get a 500 error. This happens even if I have faq.php on the server.
Any ideas what I'm doing wrong? The no-extensions is secondary, the primary goal is to redirect all requests from html to php files.
Place this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# skip POST requests
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.(php|html?)[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)(\.html?)?$ /$1.php [L,QSA]
You need to redirect
/faq.htm
/faq.php
[using redirect directive]
to /faq
now just applying rewrite rule to this later condition [/faq] to
/faq.php
It should work.
My .htaccess file is as follows:
Options -Multiviews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php
It works, but I'm wondering how it works. For example, if I type in example.com/main, I get the file at www.example.com/main.php. How do I get the .php extension if the code tells the rewriting to stop after adding the www. to the beginning of example.com?
Edit: Or should I create a unique ID only for the purpose of logging in the remembered user?
The particular behavior you're asking about comes about because the rule
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
is a 301 redirect; it instructs the browser to initiate a completely new HTTP request. The L only causes (can only cause) it to be the last rule executed for that request; the new request comes in with the correct hostname and proceeds onward.