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]
Related
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]
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
The sub-directory is /addon/ it stores all data for my sub-domains a.k.a addon domains.
In this sub-directory I also store my primary domains data, my primary domain is website.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?website.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Okay so that part is done, if I enter website.com/addon/mysecondwebsite-com I get a 404.
If I enter mysecondwebsite.com I see the contents of website.com/addon/mysecondwebsite-com.
This is great, thats what I wanted.
Now the tricky part, I already set up website.com to use website.com/addon/website-com. No need to tell me how to configure /addon/website-com for website.com. I need to disable 404 for website.com which is configured to use /addon/website-com/ but I also need to make sure if I enter website.com/addon/website-com that this directory is returned a 404.*
My rewrite conditions mention if I enter /addon/* on my primary domain (website.com) I will be returned a 404 error. This is great for my addon domains because they use /addon/ and not my primary domain. But how do I also block /addon/* but still use my primary domain?
website.com = 404 / BAD (website.com/addon/website-com)
mysecondwebsite.com = 200 / Good (website.com/addon/mysecondwebsite-com)
website.com/addon/mysecondwebsite-com = 404 / Good
website.com/addon/website-com = 404 / Good
Just so you get the full picture this is my .htaccess file for /public_html/
# Part one block direct access to /addon/ folder
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?website.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
# Part two using /addon/website-com/ as website.com directory
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteCond %{REQUEST_URI} !^/addon/website-com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /addon/website-com/$1
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteRule ^(/)?$ addon/website-com/index.php [L]
Replace your 404 handler with this:
ErrorDocument 404 /404.shtml
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+addon/ [NC]
RewriteRule (?!^404\.shtml$)^.*$ - [L,R=404,NC]
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
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
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Here is my current .htaccess code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
it is works only in removing .php extension
from
http://localhost/mysite/news.php?category=cat1&id=1
to
http://localhost/mysite/news/cat1/1/
and from
http://localhost/mysite/news.php?category=cat1&year=2011&month=10&day=25&id=1
to
http://localhost/mysite/news/2011/10/25/1
How to write complete .htaccess for the clean url above?
Try This
RewriteRule ^(.*)\/$ $1.php [NC]
for example
http://www.exapmle.com/contact-us/
Add an optional / to your pattern:
RewriteEngine On
# rewrite news articles and pass news id as a GET parameter to news.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/mysite/news/(\d+)/?$ /mysite/news.php?newsid=$1 [NC,L,QSA]
# rewrite all other page requests to .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/mysite/(.*)/?$ /mysite/$1.php [NC,L,QSA]
You could just try a simple RewriteRule:
RewriteEngine on
RewriteRule ^/?(\w+)/?$ $1.php
This tacks on .php to any file-looking url: example.com/somethin becomes example.com/somethin.php, example.com/something/else/ becomes example.com/somethin/else.php, etc.
The only problem with this is if you try to access an actual folder, like example.com/images or something.