URL Rewrite : Pointing wildcard url to its subfolder - apache

I need to show content of wildcard url to its particular subfolder ..
For Example
Right now http://youbridge.info/watchvideosonline/random-hello.html is showing content of home page , instead i need to show contents of that particular subfolder/index.php (i.e content of http://youbridge.info/watchvideosonline/)
I tried below code , but its not working
RewriteRule ^([^/]+)/?$ index.php?filter=$1 [QSA,L]

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/.*$ /$1/index.php [L]

Related

Apache Rewrite custom rules file

I have a server set up hosting a website. It uses "pretty links". I am having a problem when trying to create rules in the htaccess file.
Before I continue I would like to reference the locations I use to minimise confusion
wwww/ the wwww is the site all my folders content in and it resides in the www folder created by wamp
page.php contains the rules I want to somehow impliment and this is located in the root of my website
currently my website produces links like the following which dont work:
www.MYDOMAIN.co.uk/our-services
the link above does not work but if I manually edit the link and do this it works:
www.MYDOMAIN.co.uk/page.php?q=our-services
I need to find a way to implement this in the htaccess file and get it to add the page.php?q=
Below is my htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . wwww/index.php [L]
</IfModule>
The problem I am having is on my home page the navigation is generated and if I click a link for our services it redirects to the page www.MYDOMAIN.co.uk/our-services
What I need it to do is to hit my rule file which is in my root directory called page.php which in turn will use the our-services or whatever the query might be to give it the correct link
I know my htaccess file is currently linking back to the index file and this is why it isn't working but I have tried other methods as seen below.
ATTEMPT 1 - this just 404's or takes me to a blank page
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . wwww/page.php?q=$1 [L]
</IfModule>
ATTEMPT 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? /page.php?$1 [L]
</IfModule>
My other attempts are all similar and I get the same 404 or blank screen. This is my first time getting into Rewriting links which explains my lack of knowledge about it.
Ok try this rule from /wwww/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wwww/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ page.php?q=$1 [L,QSA]
</IfModule>
If /wwww/ is indeed your DocumentRoot then change RewriteBase line to:
RewriteBase /

Changing url with .htaccess

I have a site like "abc.com/1_en-Application.html . Now i want to change it to abc.com/application.html.
I have .htaccess like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9]+)-([0-9]+)_(.*)-(.*).html$ index.php?id=$1&page=$2&lang=$3 [L]
RewriteRule ^([0-9]+)_(.*)-(.*).html$ index.php?id=$1&lang=$2 [L]
</IfModule>
Please help me how can i do this ?
Add the 3 lines below the existing rewrite rules:
RewriteCond %{REQUEST_URI} /application.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^application.html$ index.php?id=1&lang=en [L]
If you don't have a real file called application.html in the web root directory, this will rewrite the URL and internally direct it to index.php
If application.html is a real file, it will be shown instead. In that case, the 3 lines will still work but not necessary to include.

htaccess RewriteRule not working - (404 error) from server

I'm trying to rewrite my URL from this:
http://www.example.com/admin/index.php?id=title
to:
http://www.example.com/admin/title
I'm using this code in my htaccess:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /admin/index.php?id=$1 [L]
But then when I try out rewritten URL's i get a 404 error from my server. What is the mistake I'm making? The .htaccess is in a subfolder called admin and the rewrite rule should only work for that folder.
This .htaccess should be placed inside the folder admin that must be inside your root folder:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ index.php?id=$1 [L]
The 2 conditions make sure we are not redirecting an existent file or folder and rule tells we want to extract anything not a / and use as the ID.
The RewriteBase tell us your parent folder is admin and as such we work from there and onwards.

Hide a folder from the URI with RewriteRule in a .htaccess file

I would really appreciate if you could help me building my .htaccess file.
What I want to achieve here is moving all of my domain's files and folders to a root subfolder ("mydomain") and make sure that the URL visible to my visitors still looks like
domain.com/file.extention
instead of
domain.com/mydomain/file.extention
or
domain.com/subfolder/file.extention
instead of
domain.com/mydomain/subfolder/file.extention
This is my folders tree:
/
/mydomain
/subfolder
index.php
test.php
and here is my current .htaccess file:
<IfModule mod_rewrite.c>
# System symbolic links are allowed.
Options +FollowSymlinks
# Runtime rewriting engine enabled.
RewriteEngine On
#
# BEGIN DOMAIN
#
# Make 'mydomain' subfolder the root folder for the domain.
RewriteCond %{HTTP_HOST} ^((www\.)?domain\.com) [NC]
RewriteRule ^\/?$ mydomain/ [NC,L,S=1]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?mydomain/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ mydomain/$1 [NC,L]
#
# END DOMAIN
#
</IfModule>
The problem here is that it works when I browse for
domain.com/subfolder/
but not with
domain.com/subfolder
and with
domain.com/index.php
but not with
domain.com/test.php
Thank you all,
Matteo
Changing domain.com/mydomain/file.extention to domain.com/file.extention
use this for example
RewriteRule ^mydomain/(.+)$ http://www.domain.com/ [R=301,L]
But if you redirects working just for some pages check that you clear browser cache or use another one instead

How can I set up my htaccess to do this?

I am trying to set up my htaccess file to perform these redirections:
http://www.mysite.com/about should link to http://www.mysite.com/content/pages/about.php
http://www.mysite.com/login should link to http://www.mysite.com/content/pages/login.php
http://www.mysite.com/prices should link to http://www.mysite.com/content/pages/prices.php
Thanks
To only redirect URLs you have provided you can use this kind of rule (you can add other pages to the list of you need):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(about|login|prices)$ /content/pages/$1.php [L]
To redirect ALL non-existing pages to /content/pages/PAGE_NAME.php, you can use this rule:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# do not do anything for already existing files (like images/css/js etc)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# redirect everything else
RewriteCond %{REQUEST_URI} !^/content/pages/
RewriteRule ^(.+)$ /content/pages/$1.php [L]
NOTES:
You need to place these rules into .htaccess in website root folder. If placed elsewhere some small tweaking may be required.