How to make url id parameter like a path [duplicate] - javascript

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 3 years ago.
so I've got a problem. I want to make this URL
https://example.com/l/click.php?id=something
to look like this
https://example.com/l/something
Does anyone know how to make it happen per code?
I tried editing & using this sample .htaccess code but it didnt worked :/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?users/(.*?)/?$ /users.php?name=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /users\.php\?name=([^\&\ ]+)
RewriteRule ^/?users\.php$ /users/%1? [L,R=301]

You will need to implement rewriteRule in your .htaccess file in the directory where your php files resides.
Something like create a file called .htaccess and save the code below in it
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ click.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ click.php?id=$1
On your php you will have something like
<a href = "click/$id'></a>
or
<a href = "/$id'></a>
Always remember to shut down apache and restart it for it to take effect

So, I tested some .htaccess code and made my solution.
It's pretty simple and works the best way it could!
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ click.php?id=$1 [L]
If you want to use it on your own just change the click.php to your own PHP file

Related

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.

remove the index.php WAMP

I have a site and it works to type "www.mysite.com/folder/" (if i have a index file in that folder).
It also works to type "www.mysite.com/folder/index.php"
All fine and good, but I want it so if you type /index.php it will remove the index.php on the end also if I use a form and post to index.php I don't want that to show in the url.
I have looked around and seen every solution say .htaccess rewrite, but It don't seem to be working / or its just not the same thing that I want?
or do I need to use javascript and update the address bar?
(I'm using WAMP)
EDIT:
Things I've have tried:
1
httpd.conf
AllowOverride All
2
I have enabled:
Apache modules> rewrite_module
3
I have created a .htaccess placed in my wamp/www folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
4
wamp/apps/phpmyadmin/config.inc.php
added
$cfg['index_page'] = '';
EDIT 2:
This look like it works, but it messes up my POST to index.php so it breaks my login (It don't start the session).
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
An .htaccess file is definitely the correct solution. If it isn't working, try one of these possible answer:
.htaccess not working on localhost with XAMPP
How to use .htaccess in WAMP Server?
.htaccess not working on WAMP
Update: Re-reading your question, you might be using an older htaccess script (for PHP < 5.2.6 version). I'm not sure if the script will work in current versions. Try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
The ? after index.php in final line is the difference
If above doesn't help, what version of PHP does the PHP command phpinfo() report?
<?php
phpinfo();
die();

Configure htaccess to directly access CSS and JS files but redirect all the other requests to index file [duplicate]

This question already has an answer here:
Configure htaccess to bypass direct links to CSS and Javascript Files
(1 answer)
Closed 7 years ago.
I am currently developing a system but I am positively confused as to how I am supposed to implement this. This is my simplified file structure
-.htaccess
--/public
--/public/index.php
--/project
--/project/template1/css
--/project/template2/js
--/project/all-other-files-and-folders-used
My system currently redirects all requests to the index.php, which loads the files in the project folder for all other work BUT I want the htaccess to recognize all the CSS,IMG and JS files in the Project folders and allow direct access to them.
This is the .htaccess file that I have now
RewriteEngine on
RewriteRule ^((?!public/).*)$ public/$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?cmd=$1 [PT,L]
Is this possible?
Thanks in advance
You can use:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!(?:public|project)/).+)$ public/index.php?cmd=$1 [QSA,NC,L]

Automatically adding SourceMap headers for JavaScript requests

I've started playing around with SourceMaps and am wondering if there's a way to automatically set the appropriate header automatically if a .map file exists for a JavaScript request using .htaccess instead of having to modify the original JavaScript file.
I already do something similar to serve minified JavaScript if it exists and I'm not debugging:
RewriteCond %{REQUEST_FILENAME} \.(php|js)
RewriteRule . - [E=DEBUG:true]
RewriteCond %{ENV:DEBUG} !^true$
RewriteCond %{REQUEST_URI} ^(.+)\.js$
RewriteCond %{DOCUMENT_ROOT}%1-min.js -f
RewriteRule . %1-min.js [L]
I guess it basically boils down to: how can I add an extra HTTP header if a certain file exists for a certain type of request?
UPDATE
The solution is as follows:
# If serving minified js and a SourceMap file exists, send appropriate header
RewriteCond %{REQUEST_URI} ^(.+-min\.js)$
RewriteCond %{DOCUMENT_ROOT}%1.map -f
RewriteRule . - [L,E=SOURCE_MAP:%{REQUEST_URI}.map]
Header set X-SourceMap "%{SOURCE_MAP}e" env=SOURCE_MAP
See edit made by Nev Stokes above for the final solution
RewriteCond %{REQUEST_FILENAME} \.(php|js)
RewriteRule . - [E=DEBUG:true]
RewriteCond %{ENV:DEBUG} !^true$
RewriteCond %{REQUEST_URI} ^(.+)\.js$
RewriteCond %{DOCUMENT_ROOT}%1-min.js -f
RewriteRule [^/]+\.js$ %1-min.js [L,E=SOURCE_MAP:%{REQUEST_URI}]
Header set X-SourceMap "%{SOURCE_MAP}e" env=SOURCE_MAP
I could not test the Header part as my test server doesn't have mod_headers installed.

Categories