Is there any way to hide .html extension from URL using JavaScript.
FOR ex:
mysite.html hide.html here from url
You cannot achieve this through javascript, this need to be done through .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
More information about mod_rewrite module here.
You can with html5, but also you can use url rewriting, or seo friendly urls, on the server side.
window.history.pushState({"html":'<html></html>',"pageTitle":'this is my title'},"", 'http://stackoverflow.com/mynewurl');
However keep in mind you can only change the url to one which is the same domain as the original!
There is a great library called history.js which helps with cross browser and version compatibility
Related
My word press installation resides in public_html/cushbu folder
and it will be accessed by www.example.com/cushbu so i have changed the base url's in wp-config.php
define('WP_HOME','http://www.example.com/cushbu/');
define('WP_SITEURL','http://www.example.com/cushbu/');
Also i've edited this line .htaccess file
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com/cushbu/ [NC]
the problem is i can't access the wp-admin its redirected to old url
So how can i completely change the base url??
Change the url in your database table called wp_options field's home url and site url. Change it to your new url.
outside of cushbu folder, in public_html folder, you should have .htaccess file modify that file with the following line.
# Redirect Trailing Slashes...
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(cushbu)
and WordPress source has .htaccess file edit like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cushbu/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cushbu/index.php [L]
</IfModule>
You need to change the site URL and home URL in the database too. Its in the wp_options table. I hope you have database access.
Cheers!
Follow simple steps to replace in core database url
1) You need to export your old database to local computer
2) Notepad++ editor or some other editor tool. replace (cntrl+H) in notepad++
3) First Find http://www.example.com/cushbu/ and Replace with new URL eg. http://www.newexample.com/cushbu/
4) Second Find without http www.example.com/cushbu/ and Replace with new URL eg. www.newexample.com/cushbu/
5) Final find any old url is present or not.if yes than replace by new url and save.
6) Import new replaced database to old database and login by wp-admin and click on Settings / Permalinks now it's done.
I am doing the user control panel, and I have some problems I am not sure how to do this dynamic profile link currently. example.com/profile/CroatiaGM What would be the best way to go about this, My site is mainly PHP, is it better to use js or?
I'm assuming you're looking to rewrite a URL, where you'd like to rewrite example.com/profile.php?user=CroatiaGM to example.com/profile/CroatiaGM.
in such an instance I believe this would be helpful if you don't already have a .htaccess file, I suggest you create one in your main directory/public_html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^profile/([^/]+)?$ profile.php?username=$1
RewriteRule ^profile/([^/]+)/([^/]+)?$ profile.php?username=$1&type=$2
</IfModule>
or
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)?$ $1.php?username=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?$ $1.php?username=$2&type=$3
</IfModule>
Here's a working example.
https://locationtestproject.000webhostapp.com/test/myname
I strongly advise making a back of the .htaccess before saving any changes.
https://help.dreamhost.com/hc/en-us/articles/215747748-How-can-I-redirect-and-rewrite-my-URLs-with-an-htaccess-file-
How to use .htaccess for beautiful links
https://docs.bolt.cm/4.0/howto/making-sure-htaccess-works
https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
If I need start page with dynamic language URL like that:
https://stackoverflow.com.ru./
What should I do?
Should I do a redirect from a static start page or other options are exist?
I need the right way.
Use 301 redirect by .htaccess
ru and stackoverflow.com are as examples
RewriteEngine On
RewriteCond %{HTTP_HOST} !^ru\.stackoverflow\.com$ [NC]
RewriteRule ^(.*)$ http://ru\.stackoverflow\.com/$1 [R=301,L]
Place this .htaccess file in stackoverflow.com/ directory.
I have used ht-access to hide .php file extension. Inside .htaccess file my code is :
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# End of Apache Rewrite Rules
</IfModule>
It's hiding .php file extension well. But problem is that, link inside href attribute is not opening properly.
I have two files:
public_html/afiliate/product_details.php
public_html/afiliate/afiliate_login.php
Inside product_details.php I have given link of afiliate_login.php like this
Log in
Clicking Log in I should go to a page like
example.com/afiliate/afiliate_login/
But it takes me to
example.com/afiliate/product_details/afiliate_login/
And hence a 404 error
Again notice that, if i manually type this URL
example.com/afiliate/afiliate_login/
that's OK, it goes to the page as expected.
Now how I can make links work properly?
After this code:
RewriteRule ^([^\.]+)/$ $1.php
put the below code
RewriteRule afiliate_login$ afiliate_login.php [L]
basically means that any request that comes to afiliate_login will show the data from afiliate_login.php
You got that problem because in your anchor tag you are using relative url. Since your url look like this without the file extension like, example.com/afiliate/afiliate_login/ , affiliate_login/ will be also considered as a directory and the html thinks that the anchor tag is in affiliate_login/ but it in reality it does not exists there so you get 404 error.
Previously the browser considered product_details.php as a file. but now its a folder, because its product_details/
one option available here is to update the link's like this
Log in
but its always suggested like the link below
Log in
In our application we have a payment page that we want to use SSL on because we are handling credit card information. We've already put in place rewrite rules for apache to redirect a request to the specific page to HTTPS -- which takes care of any direct requests to the payment page ( http://oursite.com/pay ).
However most navigation in our site is done via relative urls and states using ui-router in angularjs and we have found that apache does not catch these requests and so serves the page without SSL.
EX If a user clicks a link with ui-sref='pay' ui-router loads the template and refreshes the state -- at no point is a request made to the server for a new uri so apache can't redirect to https
Is there a way to force ui-router(or angular in general) to force a state to use HTTPS without having to change all links to reload the entire site?
Of course this may also be a shortcoming in our rewrite rules...Here's what we have so far
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} /pay
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]
The second set of rules is to enforce html5mode for our app.
RewriteCond %{REQUEST_FILENAME} !-f is in place so that angular can fetch the payment template for the state without needing SSL. Is this okay?
I had a similar problem, although was using $routeProvider in a SPA application. What I did was to enforce a redirect inside the controller:
var forceSSL = function () {
if ($location.protocol() !== 'https') {
$window.location.href = $location.absUrl().replace('http', 'https');
}
};
forceSSL();
This though does reload all resources. However, this happens only once when switching to SSL mode.
Note, the function is actually in a service so can be called from anywhere.
I hope this helps.