So as the title says my register page is not working anymore since i removed .php extension, so here is my .htaccess file
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
And i know that the .htaccess is the reason of this because i have tried to create account without the htaccess and it worked
One more thing to make things clear when i click submit button it just refreshes the page and the details are not inserted into the database
It turns out it was just some left gcaptcha checkup that i didnt needed anymore
Related
I am very new to .htaccess files and may have done mine wrong. I have been gathering snippets of code trying to get done what I want.
This is what I have in my file so far
I read this should be in your .htaccess file
Options +MultiViews
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
This was added to force a redirect from HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This was added to remove .php at the end of all the files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This was added to remove the showing of /index when the home link was pressed
RewriteCond %{THE_REQUEST} ^.*\/index?\ HTTP/
RewriteRule ^(.*)index\.php?$ "/$1" [R=301,L]
I have tried a lot of ideas I found on both here and other sites from Google. I have had no luck hiding the GET request.
Currently, the URL looks like https://mysite.ca/event?id=123
What I would like it to look like is either https://mysite.ca/event/123
This is hosted on Godaddy and it is just a plain PHP site if that makes any difference.
Any ideas would be great!
First of all Options +MultiViews already removes .php extension so you don't need:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
About your problem try this Rule:
RewriteRule ^event/([0-9]+)?$ event?id=$1 [NC]
Which changes url from example.com/event/<number> to example.com/event?id=<number>
Although, if your site makes infinite redirects then you should change it to:
RewriteRule ^events/([0-9]+)?$ event?id=$1 [NC]
This happens if you have some includes/headers that redirect back to event and creates infinite loop.
I am rebuilding an old website and have a bunch of old url's that I am having issues re-writing properly.
For example, some of my old URLs are structured as the following:
mydomain.com/?x=about-us **and** mydomain.com/?x=services
I would like the examples to rewrite or redirect to the following:
mydomain.com/about-us **and** mydomain.com/services
Essentially, if there is an occurrence of '?x=' in the URL I would like to strip it out.
Currently the only other cond/rule I have in .htaccess is to remove the '.php'. extensions.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This works well enough, and allows me to write my internal links without the '.php' extension, such as the following:
link
This sends me to 'mydomain.com/about-us', which is what I want. My issue is handling URLs with the '?x='
Any help would be appreciated thank you.
You may use these rules in your site root .htaccess:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?x=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=301,L,NE]
# add .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ ?x=$1 [L,QSA]
I have my hosting with 1and1, I have just got a SSL certificate. I currently have changed the .htaccess to load .php files instead of html files which works fine with this code:
RewriteEngine on
#remove the need for .php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Now I want the site to load with https, regardless of if it is entered like http://www or http:// etc. I am getting so many different ways to do this from various places as most same that I am supplying duplicate sites if I don't specify either http:// or http://www. So I think I will be solving 2 problems in one go. The code 1and1 supply is:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.sitename\.co.uk$ [NC]
RewriteRule ^(.*)$ https://www.sitename.co.uk/$1 [R=301,L]
But this does not seem to do much on its own? Can I conbine the 2 to simply load https://www.site for everything and change all links to load .php.
This works perfect
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteEngine on
#remove the need for .php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I'm actually working on a little php webiste and i decided to try to give it some nice and cleans urls using a htaccess file. I've read some docs about it and created a simple file with a few rules, things is it's working but partially.
This is what I did:
I added a RewriteRule to redirect "www.mysite.com/hello" to "www.mysite.com/index.php?action=hello".
This is working fine, problem is i want to hide the "index.php?action=" part if it ever appears. So if somoene imputs something like "www.mysite.com/index.php?action=hello" it will be converted to www.mysite.com/hello" in the url field.
For this i wrote the following:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?action=([^\ ]+)
RewriteRule ^index\.php$ /%1? [R=301,L]
Sadly it only hides the index.php part of the url, the "?action=" part is still there.
What did i do wrong?
Regards.
Edit: i'm testing this on local in wamp
You're pretty close. The regex in the rule is trying to match article.php but the condition says that the request must be for index.php, so it's unlikely the rule will ever run. Try:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?action=([^&\ ]+)
RewriteRule ^index\.php$ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?action=$1 [QSA,L]
and make sure the rule is before the rule that rewrites internally back to index.php.
So I striped all my html extensions and can now visit both the one with the extension and the one without it.
Does google see having /example.php and /example as duplicate content now?
How would I make it so only the file without the html extension shows?
my code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
The whole concept of hiding existing files but still delivering them is kind of weird, but technically it would work like the following
RewriteEngine on
RewriteRule ^(.*)\.html$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
This does a redirect from /example.html to /example and returns a http status code 301 ("Moved permanently"). This tells e.g. google that the content of this page has moved.