wildcard_charcters.sitename routing issues - ruby-on-rails

i would like to incorporate wildcard characters to my site. so previously it was
www.mysite.com/user/mike or www.mysite.com/user/dave will look like
mike.mysite.com or dave.mysite.com. i tried .htacces rewriting but those were of rewriting for sub-domains and it was creating problems with css and images.I just want that too call user function with value we pass.I use RoR MVC framework.(i'm sure .htacces solve this issue but i don't know if we can give wildcards in routes too).
and i would like to keep other links normal like www.mysite/project/dashboard or www.mysite/project/messages.
Thanks in advance.
edit
i tried this but it dosent work, it's goes to site5s default page.
Options +FollowSymLinks
RewriteEngine On
RewriteCond ^(.*)$.example.com [NC]
RewriteRule ^(.*)$ http://example.com/user/$1 [R=301,L]'

ok, finnaly i was able to do it,there will be few things which you have to do first.
paste this code in .htaccess first of all.
Options +FollowSymLinks
RewriteEngine On
// enable rewriting
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ // Check for wildcard character before example.com
RewriteCond %1 !=www // check if www is not present in URL
RewriteRule ^(.*)$ http://www.example.com/user/%1/$1 [R=302,L] // Redirect URL and replace matched wildcard character "^(.+)" in place of "$1"
Now we have defined the rules for that, now it's turn of redirection. above code won't be able to work.
for that you have to create a wildcard sub domain in from your Cpanle. Create a sub domain *.example.com and point to your public_html(you subsite if t\redirected site is a child site)

Related

I Want to Generate Search Engine Friendly urls

I Want to Generate Search Engine Friendly urls for eg:- say I have a link below like
http://www.apexengineeringproject.com/display_project.php?id=AP112&title=ADVANCED%20OFFICE%20AUTOMATION%20SYSTEM%20USING%20GSM%20AND%20MICROCONTROLLER
I Just want it to be
http://www.apexengineeringproject.com/display_project.php/AP112/ADVANCED%20OFFICE%20AUTOMATION%20SYSTEM%20USING%20GSM%20AND%20MICROCONTROLLER
I tried with rewrite in .htaccess but didnt succeeded even Im not getting how to GET parameters once link is converted to seo friendly.So anybody please help me in this situation.
EDIT:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} \/index\.php [NC]
RewriteRule (.*) apexengineeringproject.com [R=301,L]
RewriteRule ^display_project.php/([^/]+)/([^/]+) /display_project.php?id=$1&title=$2 [NC]
This is the content of my .htaccess file but problem is page gets loaded but not the styles and javascripts.
Most likely, you're referencing your script/style files using a relative file name. The browser will use the whole directory path up to the last slash before the query string for fetching relative paths.
For example, when using the page before rewrite;
http://www.apexengineeringproject.com/display_project.php
...and it looks for a script at scripts/test.js, the browser will fetch it from;
http://www.apexengineeringproject.com/scripts/test.js
When using the page after rewrite;
http://www.apexengineeringproject.com/display_project.php/AP112/ADVANCED%20OFFICE%20AUTOMATION%20SYSTEM%20USING%20GSM%20AND%20MICROCONTROLLER
...a fetch of the relative path scripts/test.js will fetch the file;
http://www.apexengineeringproject.com/display_project.php/AP112/scripts/test.js
...which presumably does not exist.
To fix the problem, just make your script paths and css paths relative to the server root, ie don't use scripts/test.js, instead use /scripts/test.js.
EDIT: Although I'd consider it slightly hacky, you could rewrite some files back to the root. Can't test this, but it should be close to what you want;
RewriteCond %{REQUEST_URI} \.(jpg|css|png|js)$ [NC]
RewriteRule display_project.php/[^/]*(.*) $1 [NC]

URL Rewriting doesn't rewrite automatically

I have this simple redirection on my website and it does not rewrite my url automatically, I have to type manual other URL to access it, what could be the problem, do I need to have something enabled in php.ini, below is the rewrite rule
RewriteEngine On
RewriteRule ^new-page-([^/]*)\.php$ /mypage.php?name=$1 [L]
If you are doing it in .htaccess you should also specify RewriteBase /.
Try
RewriteEngine On
RewriteBase /
RewriteRule ^new-page-([^/]*)\.php$ mypage.php?name=$1 [L]
This rewrites new-page-something.php tomypage.php?name=something internally.
ADDED:
Perhaps you want this:
RewriteEngine On
RewriteBase /
RewriteRule ^new-page-([^/]*)\.php$ mypage.php?name=$1 [L]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /mypage.php
RewriteCond %{QUERY_STRING} name=([^\&]*)
RewriteRule ^mypage.php$ new-page-%1.php? [R,L]
The first added RewriteCond checks whether the real request is requesting for /mypage.php to prevent a redirect loop.
The second added RewriteCond is used to match the query string for use in RewriteRule.
check your apache config (httpd.conf)
see whether it allowing to overriding the htaccess
http://httpd.apache.org/docs/2.0/howto/htaccess.html
I have the following link
www.preparationweb.com/Aptitude/Discussion/index.php?qid=26
I like it to appear it as
www.preparationweb.com/Aptitude/Discussion/26
Can you please provide me the code to be placed in .htaccess file according to the provided link. I have a godaddy hosting.

don't display .php extension in address bar(php)

First of all this method clearly working on github, for example pages showing done:
https://github.com/account
https://github.com/inbox
There is no .php extension at all + not needed ?page=account or ?page=inbox
In my opinion it's done via .htaccess.
Maybe someone knows how it should look in order to archieve same effect like github site ?
This can be achieved using mod_rewrite for apache
You put a .htaccess file in your document root and give it rules (Regular Expressions) to match the called URLs with
It looks similar to this:
RewriteEngine On
# rule to call MyPage.php if you call the URL http://yourdomain.com/MyPage
RewriteRule ^(.*)$ $1.php
# rule to add GET params
RewriteRule ^(.*)$ index.php?page=$1
There are several tutorials regarding mod_rewrite on the internet

mod_rewrite is redirecting instedad of rewriting

I must be missing something obvious, but I can't make it work
I want to have nice urls with subdomains, but instead of some directories I want to read the subdomain's content from the file:
RewriteEngine On
RewriteBase /
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^subdomain.example.com
RewriteRule (.*) http://example.com/subdomain.php
These rules works, but if I enter subdomain.example.com I am redirected to example.com/subdomain.php - but I do not want this, I just want internally rewrite the url...
Thank you very much! I tried [QSA, L], do not work.
If you replace this:
RewriteRule (.*) http://example.com/subdomain.php
With this, I suspect it will work as you are expecting:
RewriteRule (.*) subdomain.php
There is no need to rewrite the domain unless you actually want to redirect to another domain, you only need to rewrite the request to point to the appropriate file. Indeed as you discovered rewriting the domain will cause a redirect. Normally RewriteRule matches all of the request after the domain, so just the path and query.
Rather than use mod rewrite for this, if you have access to the DNS controls of your domain, you could set a catchall subdomain with a wildcard (either '%' or '*') that directs to the same local directory. There, you could have a PHP script which all requests are directed to using:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?p=$1 [L]
and this would run all the requests into that PHP file. There you can have something that checks the $_SERVER variables for the requested domain, and a checker to see the subdomain. There it could use something such as a file_get_contents() subroutine to forward the relevant data to the client, and have 404 or 403 header responses if a request is made that may be valid, but not to that subdomain.
hope that makes sense...

A little bit help in url rewriting, please!

I have a short question about url rewriting...
I have a website. Let's say http://www.example.com/
with some subsites:
http://www.example.com/a.php
http://www.example.com/b.php
etc...
and some "special" urls like
http://www.example.com/c.php?i=1#link1
http://www.example.com/c.php?i=1#link2
http://www.example.com/c.php?i=2#link1
Now I would like to write a .htaccess file to convert current urls into rewritten urls like
http://www.example.com/a/
http://www.example.com/c/1/#link1
I'm not an expert in url rewriting, so could somebody please help me?
Best reagards.
RewriteRule ^a$ a.php [L]
RewriteRule ^c/(.*)/(.*) c.php?i=$1$2
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^a.php a/
RewriteRule ^b.php b/
Should work as far as your static pages go, you can not rewrite the hash because the hash is not sent to the server (as discussed here). If you need to rewrite the hash I would suggest changing the hash to another GET variable (eg u), in that case just add this to your htaccess: RewriteRule ^c.php?i=(.*)&u=(.*) c/$1/$2. If you simply intend to leave the anchor though, you can omit it from your rewrite and everything should be fine (...becuase the server never sees the hash/pound symbol), and in that case you should add this to your code RewriteRule ^c.php?i=(.*) c/$1/.

Resources