Link not opening properly after hiding file extension using htaccess - javascript

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

Related

Locked out of wordpress admin wp-admin while trying to activate https manually [duplicate]

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.

HTML add path to sub pages

How do I add paths without .html on my webpages?
My main site: www.example.com
About Page: www.example.com/about
Another Page: www.example.com/test/contact
Create a file with the name .htaccess in your root directory
and add this code to it :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
but you need to use http server
There can be two ways to go about this:
(a) URL rewriting: In the .htaccess file in your root folder (if there isn't one already existing, create it) make the following changes:
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-d # Check that the URL doesn't point to a directory
RewriteCond %{REQUEST_FILENAME}.html -f # Check that the URL points to a file with the extension html
RewriteRule ^(.*)$ $1.html [NC, L] # Finally, make the change with a regex and flags like NC which ensures that this rule should be case-insensitive, and 'L' stops processing any more rules if this one is used.
Here is a good resource for URL rewriting: https://aloneonahill.com/blog/url-rewriting-for-beginners/
(b) Create an index.html file in each of your folders: This way the URL ends at the directory name and doesn't show the index.html leading to cleaner URLs (for e.g. example.com/about instead of example.com/index.html).
I am not sure about the issues with the second method. It does look clunky.

changed .htaccess and permalink now everything besides homepage 404s

I added this code to my .htaccess file to get rid of index.php, but now all the pages 404 (the hyperlinks are mapped to the correct url)
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
i set up my permalinks using http://1.1.1.1/%postname%/
what are the next steps in order to troubleshoot this issue?
can anyone provide me with a rewrite link and where that file may be located (I don't fully understand the other similar posts as they all wrote their own rewrite rules, where would I find that file?)
I have already installed monkeyman rewrite analyzer, but don't know where to start troubleshooting from there.
Any links or information is helpful, even if is not a direct solution to the problem, I will post my solution when completed.

Laravel - href in ignored subfolder trouble

I have a bit of trouble with in a folder that laravel is ignoring.
In my .htacces I have a line that will ignore my folder called 'doc'.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^(doc) - [L] <-- this one
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
and it works like it should.... kinda.. Example: 'localhost/doc/main.js' works fine if i type it direct into my webbrowser.
Here is my problem: in my /doc i have a 'index.html' that include/require/link some files into it from the doc dir. So in the index.html I have a line
<script data-main="./main.js" src="./vendor/require.min.js"></script>
When I go to 'localhost/doc' I get error that file cant be found (and alot others). linking to 'localhost/vendor/require.min.js'. This should be 'localhost/doc/vendor/require.min.js'
NOTE: this file is generated with ApiDocJS
Anyone have a solution for me, am stuck for about 4 hours now... am getting frustrated
I'll suggest to try to do the same in a different way.
If you're stuck for so long on a problem like that, try changing the way you are following to accomplish your goal.
Why that directory?
Why ignoring it in .htaccess?
Why not separate the logic of the app from the thing I want to hide?
Can I configure the libraries I want to use in order to specify a directory?
Can I refactor some of my code to prevent the ignore-the-dir-in-htaccess thing? (Since it's not common to do that)
That questions will move you to another direction that may or may not help you with your problem, but that's what I always do on a problem I'm stuck for more than 30 minutes, asking myself for another way of doing the same thing.

SyntaxError: expected expression, got '<' when working with .htaccess RewriteRule flatlinks

Im trying to make flat links to my site, and thats why i started to make .htaccess file in my root directory.
First i redirect to https protocol without subdomain www - and thats works right.
Second im trying to make three RewriteRules
first when there is one option second when there are two option and third if there is some text after second option slash
Options +FollowSymlinks
RewriteEngine On
RewriteBase /index.php
#redirect to right protocol and without www subdomain
#check if https is off
RewriteCond %{HTTPS} off [OR]
#or added www to domain name
RewriteCond %{http_host} ^www\.domain\.com [NC]
#if one of them - then redirect to https withot www
RewriteRule ^(.*) https://domain.com%{REQUEST_URI} [L,R=301]
#flatlink rewrite rules
#if https://domain.com/option_name OR https://domain.com/option_name/
RewriteRule ^([^/]+)/?$ index.php?option=$1 [NC,L]
#if https://domain.com/option_name/some_id OR https://domain.com/option_name/some_id/
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?option=$1&id=$2 [NC,L]
#if after second slash is some other text just ignore it
RewriteRule ^([^/]+)/([^/]+)/(.+) index.php?izvele=$1&galda_id=$2 [NC,L]
So the problem is when there is only the first of the flatlink rewrite rules everithing works as expected but when i uncoment second only or second and third rule then redirecting work as expected but stiles and javascript is not loaded and console shows this error - SyntaxError: expected expression, got '<'
Another thing that i seen and dont know why this happens is with RewriteBase - if i make it
RewriteBase /
then in first flatlink rule option is not passed as option_name but index.php
So i would be whery thankful if someone could point me in right direction to solve this problem.

Categories