URL .HTACCESS LINK SETTING [duplicate] - .htaccess

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 1 year ago.
I have a link
https://example.com/article.php?article_link=10-scientists-who-made-the-dropsy-vaccine
i want this link to have a url like
https://example.com/article/10-scientists-who-made-the-dropsy-vaccine
where the last part of the link i.e 10-scientists-who-made-the-dropsy-vaccine is dynamic and can be anything
How can i do this???

You can do this with your htaccess . Open your .htaccess file and put the following rule :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/(.+)$ /article.php?article_link=$1 [L,NC]

Related

some issue on rewriting url using htaccess [duplicate]

This question already has answers here:
How can I create friendly URLs with .htaccess?
(8 answers)
Closed 8 years ago.
When user visit "https://www.example.com/api3/SGy7bT" url then i want to load "https://www.example.com/api3/webhook3_index2.php?random=SGy7bT" page. On the browser the url will not change and it will appear like top mentioned url.
My htaccess file is exist on "/api3" folder.
Try:
RewriteEngine On
RewriteBase /api3/
RewriteCond %{THE_REQUEST} /api3/webhook3_index2\.php\?random=([^&\ ]+)
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILEAME} !-f
RewriteCond %{REQUEST_FILEAME} !-d
RewriteRule ^(.*)$ webhook3_index2.php?random=$1 [L,QSA]

.htaccess not working when url contains a path

I've searched stackoverflow and numerous websites for an answer to this. So please don't shoot me if it's already been answered on stackoverflow. I am stuck.
I just need a simple redirect where anything after my website name is put into a querystring of $target except for when a path is included in the url.
It doesn't work when a path is given.
eg)
mysite.com.au/home to mysite.com.au/?target=home
mysite.com.au/home/ to mysite.com.au/?target=home
mysite.com.au/home/something to mysite.com.au/home/something
mysite.com.au/home/something/ to mysite.com.au/home/something
mysite.com.au/home/something/file.php to mysite.com.au/home/something/file.php
The below in my .htaccess file. It only works for condition 1 above.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ?target=$1
Can somebody show me a better/proper way for url redirects or know how to do this?
I don't want to use specific 301 redirects.
Thanks for any help you can provide.
You can put this code in your htaccess (which has to be in document root folder)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /?target=$1 [L]

Remove Query string from website url [duplicate]

This question already has an answer here:
Using .Htaccess url redirection
(1 answer)
Closed 8 years ago.
i want to remove query string from my url using htaccess but i cant find any proper solutions
www.mysite.net/index.php?title=Category:Public_Companies&redirect=no&pagefrom=GET+UP
I Want
www.mysite.net/Category:Public_Companies/GET+UP
How can i do this. Any help will be appreciated.
The fast and easy way
.htaccess
RewriteEngine On
RewriteRule ^(.*)/(.*) index.php?title=$1&pagefrom=$2&redirect=no [L]
I create for all characters you need define what character you will be use.
Php file for test .htaccess frendly url
<?php print_r($_GET); ?>
put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+index\.php\?title=([^\s&]+)&redirect=no&pagefrom=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=301,NE,L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ /index.php?title=$1&redirect=no&pagefrom=$2 [L,QSA]

htaccess url with usernames [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 8 years ago.
What i wanted to do is first hide all .php extensions in my URL secondly i wanted all users to have there pages with there usernames like www.domain.com/username
however i can easily do the first with this code in my .htaccess.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)$ $1.php
Now how can i do the second part as if somebody goes to this domain www.domain.com/username server will route to www.domain.com/username.php but it should go to URL like www.domain.com/profile.php?id=username.
How can i achieve this?
Something like this, however it will redirect everything after the / to profile.php, so you have to make rules for all other urls before this, if needed.
RewriteRule (.*) profile.php?id=$1

Htaccess redirect [duplicate]

This question already has an answer here:
Closed 12 years ago.
Possible Duplicate:
How to rewrite to mobile.myUrl.com if user is mobile? (use Apache or inside Webapp?)
Hi there! I'm trying to write a rewrite rule, that would redirect every address in my domain, to index.php, like this:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule .* /index.php
The problem with this code is that in index.php I check whether user came to my website from a pc, or a mobile device, and according to that I redirect him to appropriate version (index.html, or mobi.html) - now since this rule applies I'm stuck in a redirection loop. Pls help stackoverflowers :).
Either you just exclude the pages index.html and mobi.html:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !=/index.html
RewriteCond %{REQUEST_URI} !=/mobi.html
RewriteRule .* /index.php
or you can set a GET variable in your redirected url, like header('Location: domain.com/index.html?norewrite'); and then do not rewrite the URL if it contains this variable:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{QUERY_STRING} !^(.*&)?norewrite(&.*)?$
RewriteRule .* /index.php

Resources