LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-30-2012, 08:05 AM   #1
trickynapzter
LQ Newbie
 
Registered: May 2011
Posts: 19

Rep: Reputation: 0
Question Rewrite URL in apache


Hi all, can i ask for your help? I'm in trouble in setting up my vhost in apache. Currently my site is up and running, my problem is that I can't get it to short url. Here's the scenario:

a. I have a website running on my server currently on vhost on port 80 and 443. Here is the config file:

Code:
    <VirtualHost *:80>
        ServerName wiki.company.com
        ServerAdmin infra@company.com
        ServerAlias wiki wiki.company.com

        DocumentRoot /var/www/html

        Redirect / https://wiki.company.com/

     </VirtualHost>

    <VirtualHost *:443>
        ServerName wiki.company.com
        ServerAdmin infra@company.com

        ProxyPreserveHost On
        ProxyRequests Off
        SSLProxyEngine off
        SSLEngine on
        SSLProtocol -ALL +SSLv3 +TLSv1
        SSLCipherSuite ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM
        SSLCertificateFile /etc/pki/tls/certs/server.crt
        SSLCertificateKeyFile /etc/pki/tls/certs/server.key

        DocumentRoot /var/www/html
        RedirectMatch ^/$ /wiki/

       ################################## 
        RewriteEngine On
        RewriteRule ^/?view(/.*)?$ %{DOCUMENT_ROOT}/wiki/index.php [L]
        RewriteRule ^/?$ %{DOCUMENT_ROOT}/wiki/index.php [L]
       ##################################
       <Directory /var/www/html/wiki>
             Options Indexes FollowSymLinks
             AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>

    </VirtualHost>
b. Whenever i am going to visit the login page which is https://wiki.company.com/view/Special:UserLogin. I want to rewrite it's URL to display only https://wiki.company.com/login or just https://wiki.company.com/. But my RewriteRule fails. This is what i have added to :*443

Code:
 RewriteRule ^/view/Special:UserLogin(.*) https://wiki.company.com/ [R,L]
Hope i explain myself clearly on this. Thanks
 
Old 09-30-2012, 09:21 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,
Quote:
b. Whenever i am going to visit the login page which is https://wiki.company.com/view/Special:UserLogin. I want to rewrite it's URL to display only https://wiki.company.com/login or just https://wiki.company.com/. But my RewriteRule fails. This is what i have added to :*443
I don't know how it's failing, but please note that you have another rule:
Quote:
RewriteRule ^/?view(/.*)?$ %{DOCUMENT_ROOT}/wiki/index.php [L]
that rewrites a URL starting with "/view..." to "/var/www/html/wiki/index.html"

Regards
 
Old 10-01-2012, 07:14 AM   #3
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: RHEL 7.x, SLES 11 SP2/3/4
Posts: 1,195
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
you can add an alias entry for view/Special:UserLogin

Code:
Alias   /    view/Special:UserLogin
or
Code:
Alias   /login    view/Special:UserLogin
restart your apache server
 
Old 10-01-2012, 07:58 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by deep27ak View Post
you can add an alias entry for view/Special:UserLogin

Code:
Alias   /    view/Special:UserLogin
or
Code:
Alias   /login    view/Special:UserLogin
restart your apache server
No you can't.
Alias is used to map a directory outside the DocumentRoot to some URL. In this case Special:UserLogin surely does not look like a directory name, so you cannot alias it to something else.
 
Old 10-01-2012, 03:51 PM   #5
_dkode_
LQ Newbie
 
Registered: Sep 2012
Location: kerala
Distribution: debian
Posts: 11

Rep: Reputation: 0
bathory pointed out the issue,
adding a Rewrite Condition before the ambiguous Rewrite Rule will solve the issue.
Quote:
RewriteCond %{REQUEST_URI} !^/view/Special:UserLogin
RewriteRule ^/?view(/.*)?$ %{DOCUMENT_ROOT}/wiki/index.php [L]
 
  


Reply

Tags
apache, httpd, rewritecond, rewriterule



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
handling %20 in url with apache rewrite rule jnyunt Linux - Server 3 08-09-2011 10:56 PM
Apache 1.3 mod_rewrite - how to rewrite url with port dlugasx Linux - Server 1 05-19-2009 10:34 AM
apache rewrite port based on URL.. can it? sir-lancealot Linux - Server 1 05-13-2009 02:06 AM
apache url rewrite about Canonical URLs addbbe Linux - Server 9 02-12-2009 05:21 AM
apache url rewrite gallew Linux - Server 0 08-25-2006 03:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration